python-3.4

Why doesn't my current directory show up in the path using pytest on Windows?

送分小仙女□ 提交于 2019-12-10 14:52:43
问题 I have the following folder structure; myapp\ myapp\ __init__.py tests\ test_ecprime.py and my pwd is C:\Users\wwerner\programming\myapp\ I have the following test setup: import pytest import sys import pprint def test_cool(): pprint.pprint(sys.path) assert False That produces the following paths: ['C:\\Users\\wwerner\\programming\\myapp\\tests', 'C:\\Users\\wwerner\\programming\\envs\\myapp\\Scripts', 'C:\\Windows\\system32\\python34.zip', 'C:\\Python34\\DLLs', 'C:\\Python34\\lib', 'C:\

Recursively import all .py files from all folders [duplicate]

旧街凉风 提交于 2019-12-10 14:08:08
问题 This question already has answers here : How to import other Python files? (19 answers) How to import a module given the full path? (29 answers) Closed 4 years ago . Given one root directory, I need to import all files from all folders (and folders inside other folders) under the root directory. I figured this could maybe be done with the help of os.walk() , but no idea how to import the files after "walking" through them. Is there an easy way to do this? 回答1: To import a module by name (in 3

How to save Python coding in Command Prompt as a file?

让人想犯罪 __ 提交于 2019-12-10 13:52:29
问题 I just typed an example from a book in Python34 of a running Command Prompt. but now I want to save this python program as file for future uses. Since I have never used Command Prompt before and I also searched online but most of them cannot answer. Can anyone show the solution here? Thanks. 回答1: You can save lines in ipython using %save: Usage: %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ... Options: -r: use ‘raw’ input. By default, the ‘processed’ history is used, so that magics are

Python3: print(somestring,end='\r', flush=True) shows nothing

北城余情 提交于 2019-12-10 13:47:18
问题 I'm writing a progress bar as this How to animate the command line? suggests. I use Pycharm and run this file in Run Tool Window. import time def show_Remaining_Time(time_delta): print('Time Remaining: %d' % time_delta, end='\r', flush=True) if __name__ == '__main__': count = 0 while True: show_Remaining_Time(count) count += 1 time.sleep(1) However, the code displays nothing if I run this .py file. What am I doing wrong? I tried Jogger's suggest but it's still not working if I use print

Unable to see or modify value of PYTHONHASHSEED through a module

对着背影说爱祢 提交于 2019-12-10 13:13:36
问题 Trying to see the value of PYTHONHASHSEED by using: # (this is inside module_1.py) os.environ['PYTHONHASHSEED'] raises a KeyError: Traceback (most recent call last): File "/home/black/Dev/Projects/module_1.py", line 2, in <module> os.environ['PYTHONHASHSEED'] File "/usr/lib/python3.4/os.py", line 631, in __getitem__ raise KeyError(key) from None KeyError: 'PYTHONHASHSEED' Printing the contents of os.environ by for i in sorted(os.environ): print(i) # prints: # CLUTTER_IM_MODULE # COMPIZ_BIN

Can't uninstall Python 3.4.2 from Windows 7 after system restore

我与影子孤独终老i 提交于 2019-12-10 12:53:37
问题 A couple of days after uninstalling Python 3.4.2 I had to carry out a system restore (I'm using Windows 7) due to accidentally installing a bunch of rubbish-ware that was messing with my computer even after installation. This system restore effectively "reinstalled" Python, or rather a broken version of it. I now can't uninstall it via the usual Control Panel -> Uninstall Programs tool, nor can I reinstall it using the original installer. Unfortunately Windows has not saved an earlier system

Invalid syntax using regular expression in python 3.4

夙愿已清 提交于 2019-12-10 10:07:50
问题 I am using the following expression in python 3.4 it gives syntax error but the same code works in python 2.7 block = re.compile(ur'DATA\(value\)[\S ]+\s((?:(?![^\n]+DATA\(value2\)).)*)', re.IGNORECASE | re.DOTALL) I am unsure what is the real issue in this expression 回答1: Python 3 has no ur'...' raw unicode string syntax. Use r'...' instead: block = re.compile( r'DATA\(value\)[\S ]+\s((?:(?![^\n]+DATA\(value2\)).)*)', re.IGNORECASE | re.DOTALL) If you need to create cross-Python compatible

Using Kivy with Python 3.4

我的梦境 提交于 2019-12-10 07:58:34
问题 I have installed Kivy on my Mac. OS X comes installed with Python 2.7. I wanted to use the enum feature of Python 3, so I installed Python 3.4. After much searching and oulling of hair, I was pointed to this line exec $(python -c "import os, sys; print os.path.normpath(sys.prefix)")/bin/python2.7 "$@" in the file /Applications/Kivy.app/Contents/Resources/script. I changed it to: exec /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 "$@" in the hope of forcing Kivy to use Python

Why does IDLE 3.4 take so long on this program?

女生的网名这么多〃 提交于 2019-12-10 03:14:37
问题 This question was migrated from Code Review Stack Exchange because it can be answered on Stack Overflow. Migrated 5 years ago . EDIT: I'm redoing the question entirely. The issue has nothing to do with time.time() Here's a program: import time start=time.time() a=9<<(1<<26) # The line that makes it take a while print(time.time()-start) This program, when saved as a file and run with IDLE in Python 3.4, takes about 10 seconds, even though 0.0 is printed out from time.time() . The issue is very

Installing numpy for Python 2.7 while also having Python 3.4 installed?

不想你离开。 提交于 2019-12-10 02:16:08
问题 I have both Python 2.7 and Python 3.4 (and have to have both because for the class I'm running, students have the option of using either). One student has used Python 2.7 and numpy for their project, but when I attempt to install numpy, it installs it to 3.4. I need to install it to 2.7. I'm using numpy 1.9 from this site, which I'm told is also 2.7-specific: http://sourceforge.net/projects/numpy/files/NumPy/ However, nonetheless it still goes to the 3.4 folder. Copying it to Python 2.7 didn