python-3.2

input() vs sys.stdin.read()

狂风中的少年 提交于 2021-02-07 13:44:00
问题 import sys s1 = input() s2 = sys.stdin.read(1) #type "s" for example s1 == "s" #False s2 == "s" #True Why? How can I make input() to work properly? I tried to encode/decode s1 , but it doesn't work. Thank you. 回答1: If you're on Windows, you'll notice that the result of input() when you type an 's' and Enter is "s\r" . Strip all trailing whitespace from the result and you'll be fine. 回答2: You didn't say which version of Python you are using, so I'm going to guess you were using Python 3.2

input() vs sys.stdin.read()

回眸只為那壹抹淺笑 提交于 2021-02-07 13:43:04
问题 import sys s1 = input() s2 = sys.stdin.read(1) #type "s" for example s1 == "s" #False s2 == "s" #True Why? How can I make input() to work properly? I tried to encode/decode s1 , but it doesn't work. Thank you. 回答1: If you're on Windows, you'll notice that the result of input() when you type an 's' and Enter is "s\r" . Strip all trailing whitespace from the result and you'll be fine. 回答2: You didn't say which version of Python you are using, so I'm going to guess you were using Python 3.2

eval(): can't assign to function call

点点圈 提交于 2021-02-05 08:37:09
问题 Yet another question for my cookie clicker... Here is the code I made that produces an error: cps=cps+bcps[buych] c=c-bprice[buych] eval(buych)=eval(buych)+1 cps is a variable, c is a variable, b1,b2,b3,b4,b5 are variables buych is a string (Which I get from an input() command) bcps and bprice are maps (shown below) bcps = {"b1":'1', "b2":'5', "b3":'10', "b4":'20', "b5":'25'} bprice = {"b1":'10', "b2":'20', "b3":'30', "b4":'40', "b5":'50'} So, what I'm trying to achieve is: -Take the input

Installing PyQt4 in a virtualenv

浪尽此生 提交于 2020-01-24 15:11:09
问题 I am trying to install PyQT4 in a virtualenv. I am running Python3.2.1. Here's what I've done so far: sudo apt-get install qt4-dev-tools this worked fine I downloaded PyQt-x11-gpl-4.9.5 and sip-4.14 Inside the virtualenv I installed sip. No errors came up. When I try to call: python3.2 configure.py for my PyQt it lets me accept the licence, does a bunch of stuff without errors then says: Generating the C++ source for the QtCore module... sip: Usage: sip [-h] [-V] [-a file] [-b file] [-c dir]

Installing PyQt4 in a virtualenv

旧城冷巷雨未停 提交于 2020-01-24 15:11:04
问题 I am trying to install PyQT4 in a virtualenv. I am running Python3.2.1. Here's what I've done so far: sudo apt-get install qt4-dev-tools this worked fine I downloaded PyQt-x11-gpl-4.9.5 and sip-4.14 Inside the virtualenv I installed sip. No errors came up. When I try to call: python3.2 configure.py for my PyQt it lets me accept the licence, does a bunch of stuff without errors then says: Generating the C++ source for the QtCore module... sip: Usage: sip [-h] [-V] [-a file] [-b file] [-c dir]

SQLAlchemy won't update my database

最后都变了- 提交于 2020-01-21 01:34:54
问题 I'm making a Pyramid app using SQLAlchemy-0.7.8. I'm using 64bit Python3.2. The question is, why does the following function not commit anything to the database? def create_card(sText,sCard): """ create a wildcard instance if all is well (ie,sCard match in sText) return oCard, dCard otherwise return False,False """ oMatch = re.search(sCard,sText) if oMatch: oCard = WildCard() #set up some stuff about the WildCard DBSession.add(oCard) DBSession.flush() dCard = { 'id' : oCard.id, 'span' :

Python - cxfreeze keeps saying file/directory non-existant

喜你入骨 提交于 2020-01-16 06:12:48
问题 I've got some very basic code which works, and I want to turn it into an exe. Since I'm using Python 3 because it seems so much cleaner than other Python editions, I've not been able to use Py2Exe, so I installed cxfreeze instead. Once I run cxfreeze with the following command: cxfreeze "C:\Users\pc user\Documents\Python\First project\Main.py" It says something about the directory/file not existing. That's about as in-depth as it goes. The exact error is something like "Could not find the

python centre string using format specifier

孤街醉人 提交于 2020-01-09 19:05:19
问题 I have a string called Message. Message = "Hello, welcome!\nThis is some text that should be centered!" Yeah, it's just a test statement... And I'm trying to centre it for a default Terminal window, i.e. of 80 width, with this statement: print('{:^80}'.format(Message)) Which prints: Hello, welcome! This is some text that should be centered! I'm expecting something like: Hello, welcome! This is some text that should be centered! Any suggestions? 回答1: You need to centre each line separately: '

python centre string using format specifier

試著忘記壹切 提交于 2020-01-09 19:04:46
问题 I have a string called Message. Message = "Hello, welcome!\nThis is some text that should be centered!" Yeah, it's just a test statement... And I'm trying to centre it for a default Terminal window, i.e. of 80 width, with this statement: print('{:^80}'.format(Message)) Which prints: Hello, welcome! This is some text that should be centered! I'm expecting something like: Hello, welcome! This is some text that should be centered! Any suggestions? 回答1: You need to centre each line separately: '