python-3.3

How can I more easily suppress previous exceptions when I raise my own exception in response?

▼魔方 西西 提交于 2019-11-26 21:07:45
问题 Consider try: import someProprietaryModule except ImportError: raise ImportError('It appears that <someProprietaryModule> is not installed...') When run, if someProprietaryModule is not installed, one sees: (traceback data) ImportError: unknown module: someProprietaryModule During handling of the above exception, another exception occurred: (traceback data) ImportError: It appears that <someProprietaryModule> is not installed... Perhaps I don't want the "During handling of the above exception

Tkinter create image function error (pyimage1 does not exist)

感情迁移 提交于 2019-11-26 18:37:50
问题 I'm a student from the outside world with no previous programming experience. I have been learning Python as an extension of my math class. I have been trying to create a program that generates fractals using Tkinter. The code works well on its own, but the inclusion of a user-input GUI causes it to give an error: Exception in Tkinter callback Traceback (most recent call last): File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ return self.func(*args) File "C:\Python33

Python sort() first element of list

戏子无情 提交于 2019-11-26 18:31:21
问题 I have a list that contains non specific amount of elements but every first element of the nested list is an identifier, I would like to use that identifier to sort the list in order list = [['D', 'F', 'E', 'D', 'F', 'D'],['A', 'F', 'E', 'C', 'F', 'E'],['C', 'E', 'E', 'F', 'E', 'E'],['B', 'F', 'E', 'D', 'F', 'F']] After its sorted list = [['A', 'F', 'E', 'C', 'F', 'E'],['B', 'F', 'E', 'D', 'F', 'F'],['C', 'E', 'E', 'F', 'E', 'E'],['D', 'F', 'E', 'D', 'F', 'D']] I am using python 3.3.3 回答1:

How to install pip for Python 3 on Mac OS X?

半世苍凉 提交于 2019-11-26 18:13:33
OS X (Mavericks) has Python 2.7 stock installed. But I do all my own personal Python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 3.3.3. So I need to install pyserial again. I can do it the way I've done it before, which is: Download pyserial from pypi untar pyserial.tgz cd pyserial python3 setup.py install But I'd like to do like the cool kids do, and just do something like pip3 install pyserial . But it's not clear how I get to that point. And just that point. Not interested (unless I have to be) in virtualenv yet. Travis Griggs UPDATE: This is no longer necessary

Can't use chrome driver for Selenium

匆匆过客 提交于 2019-11-26 18:06:49
问题 I'm having trouble using the Chrome driver for Selenium. I have the chromedriver downloaded and saved to C:\Chrome: driver = webdriver.Chrome(executable_path="C:/Chrome/") Using that gives me the following error: Traceback (most recent call last): File "C:\Python33\lib\subprocess.py", line 1105, in _execute_child startupinfo) PermissionError: [WinError 5] Access is denied During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Python33

Printing subscript in python

瘦欲@ 提交于 2019-11-26 16:18:57
问题 In Python 3.3, is there any way to make a part of text in a string subscript when printed? e.g. H₂ (H and then a subscript 2) 回答1: If all you care about are digits, you can use the str.maketrans() and str.translate() methods: >>> SUB = str.maketrans("0123456789", "₀₁₂₃₄₅₆₇₈₉") >>> SUP = str.maketrans("0123456789", "⁰¹²³⁴⁵⁶⁷⁸⁹") >>> "H2SO4".translate(SUB) 'H₂SO₄' Note that this won't work in Python 2 - see Python 2 maketrans() function doesn't work with Unicode for an explanation of why that's

hash function in Python 3.3 returns different results between sessions

半腔热情 提交于 2019-11-26 14:40:59
I've implemented a BloomFilter in python 3.3, and got different results every session. Drilling down this weird behavior got me to the internal hash() function - it returns different hash values for the same string every session. Example: >>> hash("235") -310569535015251310 ----- opening a new python console ----- >>> hash("235") -1900164331622581997 Why is this happening? Why is this useful? Martijn Pieters Python uses a random hash seed to prevent attackers from tar-pitting your application by sending you keys designed to collide. See the original vulnerability disclosure . By offsetting the

Removing non numeric characters from a string

故事扮演 提交于 2019-11-26 14:03:37
问题 I have been given the task to remove all non numeric characters including spaces from a either text file or string and then print the new result next to the old characters for example: Before: sd67637 8 After: sd67637 8 = 676378 As i am a beginner i do not know where to start with this task. Please Help 回答1: The easiest way is with a regexp import re a = 'lkdfhisoe78347834 (())&/&745 ' result = re.sub('[^0-9]','', a) print result >>> '78347834745' 回答2: Loop over your string, char by char and

How do I compile my Python 3 app to an .exe? [closed]

社会主义新天地 提交于 2019-11-26 12:42:38
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . How do I convert my Python app to a .exe ? I made a program with tkinter and was wondering how to make it possible for others to use. I use Python 3.3. I searched for a bit but could not find anything. 回答1: cx_Freeze does this but creates a folder with lots of dependencies. py2exe now does this and, with the -