python-3.3

regex (vim) for print … to print(…) for python2 to python3

自作多情 提交于 2019-11-30 02:31:57
问题 This post is helpful only if you have strings inside of the print command. Now I have tons of sourcecode with a statement such as print milk,butter which should be formatted to print(milk,butter) And capturing the end of the line with \n was not sucessfull. Any hints? 回答1: I am not familiar with 2to3, but from all the comments, it looks like the correct tool for the job. That said, perhaps we can use this question as an excuse for a short lesson in some vim basics. First, you want a pattern

Does using virtualenvwrapper with Python3.3 mean I cannot (or should not) be using pyvenv?

我怕爱的太早我们不能终老 提交于 2019-11-30 00:45:59
问题 Virtualenvwrapper is a user-friendly shell around Python's virtualenv. Python 3.3 ships with pyvenv built into the standard library, which aims to supercede virtualenv. But if I install Virtualenvwrapper on Python3.3, it still installs virtualenv, leading me to believe it doesn't use 'pyvenv' under the covers. Presumably this doesn't really matter - if I wish to use virtualenvwrapper on Python3.3 I should happily let it use virtualenv instead of pyvenv, and will (for the moment) suffer no ill

Python : meaning of end='' in the statement print(“\\t”,end='') [duplicate]

非 Y 不嫁゛ 提交于 2019-11-30 00:03:23
This question already has an answer here: python print end=' ' 13 answers This is the function for printing all values in a nested list (taken from Head first with Python). def printall(the_list, level): for x in the_list: if isinstance(x, list): printall(x, level=level + 1) else: for tab_stop in range(level): print("\t", end='') print(x) The function is working properly. The function basically prints the values in a list and if there is a nested list then it print it by a tab space. Just for a better understanding, what does end=' ' do? I am using Python 3.3.5 For 2.7 f = fi.input( files =

Using True/False as keys - how/why does this work?

天涯浪子 提交于 2019-11-29 18:08:16
问题 I am comfortable using this simple syntax for initializing a dictionary d = {'a':'Apple','b':'Bat'}; Today, while reading a page, I encountered this weird piece of code {True:0, False:1}[True]; I was wondering why/how that could work? True and False are reserved keywords, and so, that crazy syntax should be meaningless (for the compiler), but it is not. >>> d = {True:0, False:1}; >>> d {False: 1, True: 0} And this gets crazier >>> d = dict(True = 0, False = 1); SyntaxError: assignment to

Using the crypt module in Windows?

青春壹個敷衍的年華 提交于 2019-11-29 14:50:11
In IDLE and Python version 3.3.2, I try and call the python module like so: hash2 = crypt(word, salt) I import it at the top of my program like so: from crypt import * The result I get is the following: Traceback (most recent call last): File "C:\none\of\your\business\adams.py", line 10, in <module> from crypt import * File "C:\Python33\lib\crypt.py", line 3, in <module> import _crypt ImportError: No module named '_crypt' However, when I execute the same file adams.py in Ubuntu, with Python 2.7.3, it executes perfectly - no errors. I tried the following to resolve the issue for my Windows &

subprocess stdin buffer not flushing on newline with bufsize=1

戏子无情 提交于 2019-11-29 14:34:20
I have two small python files, the first reads a line using input and then prints another line a = input() print('complete') The second attempts to run this as a subprocess import subprocess proc = subprocess.Popen('./simp.py', stdout=subprocess.PIPE, stdin=subprocess.PIPE, bufsize=1) print('writing') proc.stdin.write(b'hey\n') print('reading') proc.stdout.readline() The above script will print "writing" then "reading" but then hang. At first I thought this was a stdout buffering issue, so I changed bufsize=1 to bufsize=0 , and this does fix the problem. However, it seems it's the stdin that's

Python blockless subproccess input with constant output on Windows

倾然丶 夕夏残阳落幕 提交于 2019-11-29 13:04:45
I am trying to run a command with subproccess and the _thread modules. The subproccess has a stream of output. To combat this I used two threads, one constantly prints new lines and the other is checking for input. When I pass the subproccess input through proc.stdin.write('Some string') it returns 1 and then I get no output. Communicate doesn't work as per most other questions I have read because it blocks waiting for the EOF although it does print the first line of the whatever was going to be returned. I saw a few solutions using 'pty' but it is not supported on Windows. The file in the

Psycopg2 fails to install on python 3 with pip issuing a fatal error

时光总嘲笑我的痴心妄想 提交于 2019-11-29 11:08:15
$ yum install python3 postgresql python-devel libpqxx-devel Loaded plugins: langpacks, refresh-packagekit Package python3-3.3.2-8.fc20.x86_64 already installed and latest version Package postgresql-9.3.2-2.fc20.x86_64 already installed and latest version Package python-devel-2.7.5-9.fc20.x86_64 already installed and latest version Package 1:libpqxx-devel-3.2-0.5.fc20.x86_64 already installed and latest version Nothing to do I am trying to install psycopg2 in my virtualenv to connect django with the postgresql database. In Fedora 19 and postgresql-9.2 the path to pg_config was: /usr/pgsql-9.2

Simultaneous .replace functionality

[亡魂溺海] 提交于 2019-11-29 10:31:26
I have already converted user input of DNA code (A,T,G,C) into RNA code (A,U,G,C) . This was fairly easy RNA_Code=DNA_Code.replace('T','U') Now the next thing I need to do is convert the RNA_Code into it's compliment strand. This means I need to replace A with U, U with A, G with C and C with G, but all simultaneously. if I say RNA_Code.replace('A','U') RNA_Code.replace('U','A') it converts all the As into Us then all the Us into As but I am left with all As for both. I need it to take something like AUUUGCGGCAAA and convert it to UAAACGCCGUUU . Any ideas on how to get this done?(3.3) Use a

Given a method, how do I return the class it belongs to in Python 3.3 onward?

喜你入骨 提交于 2019-11-29 10:25:35
Given x = C.f after: class C: def f(self): pass What do I call on x that will return C ? The best I could do is exec ing a parsed portion of x.__qualname__ , which is ugly: exec('d = ' + ".".join(x.__qualname__.split('.')[:-1])) For a use case, imagine that I want a decorator that adds a super call to any method it's applied to. How can that decorator, which is only given the function object, get the class to super (the ??? below)? def ensure_finished(iterator): try: next(iterator) except StopIteration: return else: raise RuntimeError def derived_generator(method): def new_method(self, *args,