python-3.4

Get system information(CPU speed-Total RAM-Graphic Card model etc.) under Windows

限于喜欢 提交于 2019-12-03 03:28:42
I searched a lot but couldn't find anything useful. Is this possible to get system information like; CPU: Intel Core i7-3770K CPU @3.5Ghz RAM: 8GB Graphic Card: NVIDIA GeForce GTX 680 under Windows? How can I reach this output? Edit: platform.processor() is not giving the output that I want. So that is useless for me. HEADLESS_0NE I've been wondering how to do this myself for a while now, so I dug around a bit and came up with this solution using wmi (which requires pywin32 ). Of course, it goes without saying, this only works on Windows machines (and the question has the Windows tag). import

lxml.etree.XML ValueError for Unicode string

老子叫甜甜 提交于 2019-12-03 02:24:08
I'm transforming an xml document with xslt . While doing it with python3 I had this following error. But I don't have any errors with python2 -> % python3 cstm/artefact.py Traceback (most recent call last): File "cstm/artefact.py", line 98, in <module> simplify_this_dataset('fisheries-service-des-peches.xml') File "cstm/artefact.py", line 85, in simplify_this_dataset xslt_root = etree.XML(xslt_content) File "lxml.etree.pyx", line 3012, in lxml.etree.XML (src/lxml/lxml.etree.c:67861) File "parser.pxi", line 1780, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:102420) ValueError:

Auto register Django auth models using custom admin site

允我心安 提交于 2019-12-03 01:43:36
I implemented authentication management using Django auth with the default admin site but then I wanted to use my own AdminSite to rewrite some behaviors: class OptiAdmin(admin.AdminSite): site_title = "Optimizer site's admin" #...Other stuff here Then registered my own models: admin_site = OptiAdmin(name='opti_admin') admin.site.register(MyModel, MyModelAdmin) #Other stuff here But when I go to the admin site I am only able to see the models I just registered, which sounds fair to me but I would like to see all the other apps models in this new custom site including the auth's users and

What is a DynamicClassAttribute and how do I use it?

偶尔善良 提交于 2019-12-03 01:22:52
As of Python 3.4, there is a descriptor called DynamicClassAttribute . The documentation states: types.DynamicClassAttribute(fget=None, fset=None, fdel=None, doc=None) Route attribute access on a class to __getattr__ . This is a descriptor, used to define attributes that act differently when accessed through an instance and through a class. Instance access remains normal, but access to an attribute through a class will be routed to the class’s __getattr__ method; this is done by raising AttributeError . This allows one to have properties active on an instance, and have virtual attributes on

'b' character added when using numpy loadtxt

佐手、 提交于 2019-12-03 00:48:53
I tried to create an array from a text file. I saw earlier that numpy had a method loadtxt , so I try it, but it add some junk character before each row... # my txt file .--``--. .--` `--. | | | | `--. .--` `--..--` # my python v3.4 program import numpy as np f = open('tile', 'r') a = np.loadtxt(f, dtype=str, delimiter='\n') print(a) # my print output ["b' .--``--. '" "b'.--` `--.'" "b'| |'" "b'| |'" "b'`--. .--`'" "b' `--..--` '"] What are these 'b' and double quotes ? And where do they come from ? I tried some solution picked from internet, like open the file with codecs, change the dtype by

How to create a loop in Python [duplicate]

China☆狼群 提交于 2019-12-02 23:53:19
问题 This question already has answers here : While loop user input in range (2 answers) Closed 5 years ago . This is my code: my_Sentence = input('Enter your sentence. ') sen_length = len(my_Sentence) sen_len = int(sen_length) while not (sen_len < 10 ): if sen_len < 10: print ('Good') else: print ('Wo thats to long') break I'm trying to make the program ask the user continuously to write a sentence, until it is under 10 characters. I need to know how to have the program as for a sentence again,

VIM: Use python3 interpreter in python-mode

我与影子孤独终老i 提交于 2019-12-02 19:39:42
I have recently switched to vim and configured it for Python-programming using this tutorial. Before, I have made sure that vim supports python3 (vim --version shows +python/dyn and +python3/dyn) using this article. But when executing a file from python-mode , still the python2.7 interpreter is chosen. How can I configure vim (or the python-mode) to run files on the python3 interpreter? My OS is Ubuntu 14.04 x64. Thanks in advance! Try adding this to your .vimrc file let g:pymode_python = 'python3' I found this in the help docs. In vim type: :help python-mode By default, vim is not compiled

How to create a loop in Python [duplicate]

柔情痞子 提交于 2019-12-02 15:14:22
This question already has an answer here: While loop user input in range 2 answers This is my code: my_Sentence = input('Enter your sentence. ') sen_length = len(my_Sentence) sen_len = int(sen_length) while not (sen_len < 10 ): if sen_len < 10: print ('Good') else: print ('Wo thats to long') break I'm trying to make the program ask the user continuously to write a sentence, until it is under 10 characters. I need to know how to have the program as for a sentence again, but I think the simplest way would be to have the code start from the top; but I'm not surte how to do that. Can someone help?

Getting error: write() takes no keyword arguments

♀尐吖头ヾ 提交于 2019-12-02 14:50:54
gd = open("gamedata.py" , "rb+") gd.write(CharHealth = 100) gd.close I'm receiving the error message: write() takes no keyword arguments, and I cannot figure out why. My best interpretation is that the code is trying to interpret (CharHealth = 100) as a keyword argument instead of writing it to gamedata.py. I want to write (CharHealth = 100) (as a line of code) along with other code to gamedata.py If you want to write text, then pass in a bytes object , not Python syntax: gd.write(b'CharHealth = 100') You need to use b'..' bytes literals because you opened the file in binary mode. The fact

Python3 project remove __pycache__ folders and .pyc files

主宰稳场 提交于 2019-12-02 13:52:56
What is the BEST way to clear out all the __pycache__ folders and .pyc/.pyo files from a python3 project. I have seen multiple users suggest the pyclean script bundled with Debian, but this does not remove the folders. I want a simple way to clean up the project before pushing the files to my DVS. V. Gamula You can do it manually with the next command: find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf This will remove all *.pyc files and __pycache__ directories recursively in the current directory. I found the answer myself when I mistyped pyclean as pycclean: No command 'pycclean'