python-idle

How do I pass variables around in Python?

浪子不回头ぞ 提交于 2019-12-25 18:36:50
问题 I want to make a text-based fighting game, but in order to do so I need to use several functions and pass values around such as damage, weapons, and health. Please allow this code to be able to pass "weapons" "damage" "p1 n p2" throughout my code. As you can see I have tried using parameters for p1 n p2, but I am a little bit a newbie. import random def main(): print("Welcome to fight club!\nYou will be fighting next!\nMake sure you have two people ready to play!") p1=input("\nEnter player 1

How can I create my own “hint” when calling a function in IDLE?

北战南征 提交于 2019-12-25 09:28:45
问题 I know my question might be confusing, it's hard to ask something you don't know what it is exactly (I'm going to call it 'hint' ), so my apologies for that. Having that said, here it is what I mean ( the text in the white box ): My questions are: How can I make my own hint (and customize it) text when calling a function? What is it exactly? What does the text in this example mean? 回答1: IDLE calls the popup a 'calltip'. For a module defined in python code with a def statement, it shows the

Python IDLE script does not show output of subprocess but cmd.exe does

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 07:01:28
问题 I'm using Python 2.7.6 and IDLE on Windows 7. I have 2 Python scripts: script.py: import subprocess, os, sys print("hello 1") mypath = os.path.abspath(__file__) mydir = os.path.dirname(mypath) start = os.path.join(mydir, "script2.py") subprocess.call([sys.executable, start, "param"]) print("bye 1") and script2.py that is being called by the previous script: import sys print "hello 2" print (sys.argv[1]) print "bye 2" If I run script.py with cmd.exe shell I get the expected result: C:\tests

Compare two same strings but get different results in IDLE

大城市里の小女人 提交于 2019-12-25 06:48:08
问题 I'm using python 2.7.2 with built-in IDLE on windows 7 x64, and found a very strange thing: >>> a = "aaa" >>> b = "aaa" >>> print a is b True >>> print a == b True >>> print "%s , %s" % (id(a), id(b)) 43872224 , 43872224 >>> This is normal, but, if the string contains a space: >>> x = "x x" >>> y = "x x" >>> print x is y False >>> print x == y True >>> print "%s , %s" % (id(x), id(y)) 43872008 , 43872128 >>> Notice x is y is False ! And they have different ids! I tried these code in PyCharm,

why doesn't NumPy import in idle 3.30 on Ubuntu 12.10 64 Bit

笑着哭i 提交于 2019-12-25 04:11:09
问题 I installed NumPy by running the following in a linux shell: sudo apt-get install python-numpy In Idle for python 3.30 when I import numpy it outputs the following: Python 3.3.0 (default, Sep 29 2012, 17:14:58) [GCC 4.7.2] on linux Type "copyright", "credits" or "license()" for more information. >>> import numpy Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import numpy File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 137, in <module> from . import

Do the triple-quoted (docstring) messages in Python appear while typing in IDEs other than IDLE?

百般思念 提交于 2019-12-24 11:14:38
问题 I usually write scripts to calculate or process things for my own consumption. Now I'm trying to write scripts for others. I use both IDLE and a terminal, but I like just like the IDLE interface and find it more helpful. Today I "discovered" that I can add triple-quoted text under class and def and see them in real time when using IDLE, and I realize I can use those to help others know how to use these classes and methods. But if run from a terminal this is all lost. Question: Is it only IDLE

How do I make backslash (\) work in IDLE?

旧巷老猫 提交于 2019-12-24 10:15:52
问题 I use a Mac and I use Shift + Alt + / when I want to type a \ . I'm trying to learn Python and as you can see \ works fine, but not in IDLE. How do I make backslash (\) work in IDLE? 回答1: Since this problem still persists on OSX 10.8 with python 2.7.5 and 3.3.2 and since this is the first google hit when searching for backslash idle here is a more practical solution instead of copy and pasting: Go to: idle->preferences->keys Under Action-Keys replace: expand-word <Option-Key-Slash> with

PATH issues with homebrew-installed Python 2 and Python 3 on OSX

一世执手 提交于 2019-12-24 09:44:44
问题 I'm relatively new to programming and have searched 'til my fingertips were blue, but can't seem to find a solution to the problem I'm having. I have homebrew-installed versions of Python 2 and Python 3 on OSX and I can't seem to get the proper PATH/PYTHONPATH in my .bash_profile in order to be able to import modules properly in both versions in IDLE. I can, however, import modules when running Python 2 or Python 3 directly in a shell window. I am launching IDLE via terminal so it should

Turning in an item in a 2d array a specific colour based on user input

房东的猫 提交于 2019-12-24 08:57:03
问题 I have the following 2d array, displaying as a matrix. I wish to be able to specify the index number of a specific element in the 2d array and turn that number RED (or any colour). Can anyone point me in the right direction please? Code so far: >>> grid=[[28, 27, 26, 25,24,23,22], [21,20,19, 18, 17, 16, 15], [8, 9, 10, 11, 12, 13, 14], [7, 6, 5, 4, 3, 2, 1]] >>> for i in grid: print(i) Output: [28, 27, 26, 25, 24, 23, 22] [21, 20, 19, 18, 17, 16, 15] [8, 9, 10, 11, 12, 13, 14] [7, 6, 5, 4, 3,

Python & Pygame: Can't get out of paused state

馋奶兔 提交于 2019-12-24 08:00:00
问题 I'm new to Python and Pygame and I programmed a little game and tried to implement a pause menu. While I can get to the pause menu I can't get out of it. I followed a tutorial by sentdex and changed the code a bit to my liking. I'm working with Python-Idle but I don't get any error messages there either so I have no idea what I'm doing wrong. import pygame import time import random import shelve pygame.init() display_width = 800 display_height = 600 black = (0,0,0) white = (255,255,255)