python-3.3

Python console and text output from Ping including \\n\\r [duplicate]

半世苍凉 提交于 2019-12-05 21:52:37
This question already has answers here : Convert bytes to a string (18 answers) Closed 6 years ago . I dont know what is happening, but when I am printing to the console or to a text file, the newline (\n) is not functioning but rather showing in the string. Any idea how to avoid this in both the console and the text file? My code: import subprocess hosts_file = open("hosts.txt","r") lines = hosts_file.readlines() for line in lines: line = line.strip() ping = subprocess.Popen(["ping", "-n", "3",line],stdout = subprocess.PIPE,stderr = subprocess.PIPE) out, error = ping.communicate() out = out

Heroku push rejected due to pip/distribute bug. What's the workaround?

人走茶凉 提交于 2019-12-05 18:42:35
My local git/virtualenv is using pip version 1.3.1. When I try to push my Python 3.3.2 app to Heroku, I get Downloading/unpacking distribute==0.6.34 (from -r requirements.txt (line 5)) Running setup.py egg_info for package distribute Traceback (most recent call last): File "<string>", line 3, in <module> File "./setuptools/__init__.py", line 2, in <module> from setuptools.extension import Extension, Library File "./setuptools/extension.py", line 5, in <module> from setuptools.dist import _get_unpatched File "./setuptools/dist.py", line 103 except ValueError, e: ^ SyntaxError: invalid syntax

Python - convert set-cookies response to dict of cookies

我是研究僧i 提交于 2019-12-05 18:26:44
How to convert the response['set-cookie'] output string from httplib2 response like "cookie1=xxxyyyzzz;Path=/;Expires=Wed, 03-Feb-2015 08:03:12 GMT;Secure;HttpOnly, cookie2=abcdef;Path=/;Secure" to {'cookie1':'xxxyyyzzz','cookies2':'abcdef'} Use http.cookies : >>> c = "cookie1=xxxyyyzzz;Path=/;Expires=Wed, 03-Feb-2015 08:03:12 GMT;Secure;HttpOnly, cookie2=abcdef;Path=/;Secure" >>> from http.cookies import SimpleCookie >>> cookie = SimpleCookie() >>> cookie.load(c) >>> cookie <SimpleCookie: cookie1='xxxyyyzzz' cookie2='abcdef'> >>> {key: value.value for key, value in cookie.items()} {'cookie1':

Python 3.3 can't import Crypt

回眸只為那壹抹淺笑 提交于 2019-12-05 16:36:43
When I type in import Crypt on the command line it says: >>>import crypt Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python33\lib\crypt.py", line 3, in <module> import _crypt ImportError: No module named '_crypt' casevh The crypt module is an interface to the Unix crypt library which is used for encrypting Unix passwords. It is documented as not being available on Windows. It is not a general purpose cryptography library. If all you're looking for is an implementation of crypt(3) , I've knocked up a pure-Python implementation here , ported from this public

What is PasteDeploy and do I need to learn it if Eggs in Python are considered gone?

泄露秘密 提交于 2019-12-05 05:40:41
I'm quite new to Python. I've downloaded the Pyramid Framework and have been trying to understand it. It uses many separate tools for its work. For example some PasteDeploy . I tried to read PasteDeploy 's manual but can't understand anything. There is almost no valuable examples and explanation. Just syntax. All I understood is that it uses .egg format everywhere. It is based on .egg format: [composite:main] use = egg:Paste#urlmap [app:home] use = egg:Paste#static [app:blogapp] use = egg:BlogApp At the same time I found that .egg format is going to be thrown away from Python's package's

Using pySerial with Python 3.3

*爱你&永不变心* 提交于 2019-12-05 04:35:46
I've seen many code samples using the serial port and people say they are working codes too. The thing is, when I try the code it doesn't work. import serial ser = serial.Serial( port=0, baudrate=9600 # parity=serial.PARITY_ODD, # stopbits=serial.STOPBITS_TWO, # bytesize=serial.SEVENBITS ) ser.open() ser.isOpen() print(ser.write(0xAA)) The error it gives me is : "SerialException: Port is already opened". Is it me using python3.3 the problem or is there something additional I need to instal ? Is there any other way to use COM ports with Python3.3 ? P_Rein So the moral of the story is.. the port

Parallel Disk I/O

僤鯓⒐⒋嵵緔 提交于 2019-12-05 02:03:47
问题 I have several logfiles that I would like to read. Without loss of generality, let's say the logfile processing is done as follows: def process(infilepath): answer = 0 with open (infilepath) as infile: for line in infile: if line.startswith(someStr): answer += 1 return answer Since I have a lot of logfiles, I wanted to throw multiprocessing at this problem (my first mistake: I should have probably used multi-threading; someone please tell me why) While doing so, it occurred to me that any

Does PEP 412 make __slots__ redundant?

隐身守侯 提交于 2019-12-04 23:54:09
PEP 412 , implemented in Python 3.3, introduces improved handling of attribute dictionaries, effectively reducing the memory footprint of class instances. __slots__ was designed for the same purpose, so is there any point in using __slots__ any more? In an attempt to find out the answer myself, I run the following test, but the results don't make much sense: class Slots(object): __slots__ = ['a', 'b', 'c', 'd', 'e'] def __init__(self): self.a = 1 self.b = 1 self.c = 1 self.d = 1 self.e = 1 class NoSlots(object): def __init__(self): self.a = 1 self.b = 1 self.c = 1 self.d = 1 self.e = 1 Python

How do you set the position of a grid using Tkinter?

旧时模样 提交于 2019-12-04 17:38:40
Is it even possible to set the absolute position of a grid within Tkinter? I am trying to create a GUI that looks like the one below, but I am probably going about it the wrong way. So if it is possible, how do you set the grid position? Target GUI: This is how my GUI is turning out, so far: As you can see, my New Contact needs to be on the right, while the Contact List should be on the left. I understand how to move the Contact List using absolute values, but can I do the same for my grid elements? Or should I use absolute values with all of them, combined with padding? Currently, this is my

Getting exception details in Python

懵懂的女人 提交于 2019-12-04 16:56:01
问题 I have to open & write to about 10 different files all within the same loop. e.g: for i in range(0,10): try: a=5 file1 = open("file1.txt",'w+') file2 = open("file2.txt",'w+') #... etc print(str(a),file=file1) print(str(a)+"hi",file=file2) # ... etc except: #error handling Now what I'd like to do is be able to get specific exception information such as what file was being opened/written to within the general exception. From my current understanding, I'd have to do something like this to