python-3.4

How to use lists in conditionals

会有一股神秘感。 提交于 2019-12-12 02:12:17
问题 I asked a question a couple of hours ago, but it got closed as a duplicate. I was asking if I could use the index of lists to validate answers. This was my original code: message = input("Problem: ") for item in keyword_list: if item in message: if item == "screen" or item == "cracked" or item == "blank": subp.call("screen.txt", shell=True) ...and keyword_list: keyword_list = ["screen", "cracked", "blank"] etc.... I got told (as an answer to the question) to do this instead: message = input(

python 2.7 to python 3.4 error unsupported operand type(s) for %: 'bytes' and 'dict'

允我心安 提交于 2019-12-12 01:46:36
问题 I got the following code from How do I get a raw, compiled SQL query from a SQLAlchemy expression? and it worked fine until we moved from Python 2.7 to Python 3.4. I've made a few changes though I'm stuck on return (comp.string.encode(enc) % params).decode(enc) with the error unsupported operand type(s) for %: 'bytes' and 'dict' def compile_query(query): dialect = query.session.bind.dialect statement = query.statement comp = compiler.SQLCompiler(dialect, statement) comp.compile() enc =

Can I copy attributes from one widget to another in Kivy?

左心房为你撑大大i 提交于 2019-12-11 20:56:42
问题 I have 2 widgets, I need to copy all attributes (pos, size, canvas, etc.) from one widget to another somehow (and then move the last to new pos). Probably I can copy attributes one by one, but is there some built-in function? It seems Python's copy makes only shell copy (I can't move duplicate etc.) and deepcopy fails. 回答1: One thing you can do is to make use of the copy function in python. This does not copy all the pos/size values but you will have all the attributes. Ex: from copy import

Python subprocess.Popen() with Pygame , how to tell Pygame wait untill subprocess is done

萝らか妹 提交于 2019-12-11 20:02:50
问题 I have a major issue that too many Pygame users has, I want to take input from user in Pygame. I probably check all informations in internet,include stackoverflow, nothing solved. So I decide to make a solution, I created another Python script(I convert it to .exe so subprocess can open it) that asking question to user before Pygame is running, after then that script saving user's data into a .txt file(like a database).Then in Pygame I opening that .txt file and taking the data. Therocially

Adding multiple elements to a list in Python

心已入冬 提交于 2019-12-11 13:59:45
问题 I am trying to write something in Python that will be like a piano. Each number that the user enters will play a different sound. The user is prompted for how many keys they want to be able to press (iterations). They will be prompted for a number for a sound the same amount of times as they entered for iterations. Each number is a different sound. It will play the sounds. I am having trouble with the userNum function. I need all of the numbers that they enter for sounds to append to a list,

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 13: ordinal not in range(128), regarding reading in files

こ雲淡風輕ζ 提交于 2019-12-11 13:16:00
问题 I always get this error UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 13: ordinal not in range(128) when ever I try to read in a file to my python program that has an 's. For example the word "It's" would crash my program and I would get this error. Why does it do this? def readInFile(fileName): inputFile = open(fileName, 'r') SomeInput = inputFile.read() inputFile.close() return SomeInput 回答1: I'm in a python class right now and kept running into the same problem the

Using Twain Module in Python

喜欢而已 提交于 2019-12-11 12:10:50
问题 I have 64 bit Windows and 64 bit Python . In the twain docs said : supports only 32 bit . I have used twain data source to install my 64 bit machine and used this code to connect scanner device: import twain sm = twain.SourceManager(0) ss = sm.OpenSource() ss.RequestAcquire(0,0) rv = ss.XferImageNatively() if rv: (handle, count) = rv twain.DIBToBMFile(handle, 'image.bmp') When I run the app. a windows opens like : so why this window is empty . The scanner device will show in this window ? 来源:

Writing to a file prints integers to my IDLE shell

删除回忆录丶 提交于 2019-12-11 11:52:53
问题 Writing to a file prints integers to my IDLE shell. They seem to range from 15-40 and there's one for every line printed to my file. This only occurs if I write the statement directly in IDLE, outside of a function. This causes the integers to print: >> file = open('filename', 'w') >> for element in list: file.write('{}\n'.format(element)) while this doesn't: >> def print_to_file(): file = open('filename', 'w') for element in list: file.write('{}\n'.format(element)) file.close() >> print_to

No module named 'passlib'

左心房为你撑大大i 提交于 2019-12-11 11:46:22
问题 How to fix from passlib.hash import sha256_crypt ImportError: No module named 'passlib' I have already installed in using pip install passlib and it says Requirement already satisfied (use --upgrade to upgrade): passlib in c:\python34\lib\site-packages Cleaning up... How do you fix this thanks 回答1: There is an import resolution "issue" with passlib, but I expected that it would not find sha256_crypt instead of not finding passlib. Firstly, I would ensure that you have the passlib module

Python 3: Loops, list comprehension and map slower compared to Python 2?

江枫思渺然 提交于 2019-12-11 10:48:47
问题 I am currently learning Python 3 and thought some speed comparison could be neat. Thus, I created some in-place and some temporary list functions, which simply add 1 to a long list of integers. However, the results were really surprising to me...it seems that Python 3 is slower in every use case: different tested for loops, a while loop, the map function, and list comprehensions. Of course (see the code below) it just comparison of in-place list mutations or loops that build up and return a