python-3.4

How do I escape forward slashes in python, so that open() sees my file as a filename to write, instead of a filepath to read?

三世轮回 提交于 2019-12-03 12:18:05
Let me preface this by saying I'm not exactly sure what is happening with my code; I'm fairly new to programming. I've been working on creating an individual final project for my python CS class that checks my teacher's website on a daily basis and determines if he's changed any of the web pages on his website since the last time the program ran or not. The step I'm working on right now is as follows: def write_pages_files(): ''' Writes the various page files from the website's links ''' links = get_site_links() for page in links: site_page = requests.get(root_url + page) soup = BeautifulSoup

Python AES encryption without extra module

人走茶凉 提交于 2019-12-03 12:06:28
Is it possible to encrypt/decrypt data with AES without installing extra modules? I need to send/recieve data from C# , wich is encrypted with the System.Security.Cryptography reference. UPDATE I have tried to use PyAES, but that is too old. I updated some things to make that work, but it didn't. I've also can't install because it latest version is 3.3 while my version is 3.4 . The available Cryptographic Services available in the Standard Library are those . As you can see AES is not listed, but is suggest to use pycrypto which is an extra module . You just have to install it using pip , or

lxml.etree.XML ValueError for Unicode string

梦想的初衷 提交于 2019-12-03 12:02:42
问题 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

Auto register Django auth models using custom admin site

不羁的心 提交于 2019-12-03 11:15:28
问题 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

What is a DynamicClassAttribute and how do I use it?

北城余情 提交于 2019-12-03 10:55:07
问题 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

Discovering keys using h5py in python3

删除回忆录丶 提交于 2019-12-03 10:17:35
In python2.7 , I can analyze an hdf5 files keys use $ python >>> import h5py >>> f = h5py.File('example.h5', 'r') >>> f.keys() [u'some_key'] However, in python3.4 , I get something different: $ python3 -q >>> import h5py >>> f = h5py.File('example.h5', 'r') >>> f.keys() KeysViewWithLock(<HDF5 file "example.h5" (mode r)>) What is KeysViewWithLock , and how can I examine my HDF5 keys in Python3? From h5py's website ( http://docs.h5py.org/en/latest/high/group.html#dict-interface-and-links ): When using h5py from Python 3, the keys(), values() and items() methods will return view-like objects

Please explain “Task was destroyed but it is pending!”

断了今生、忘了曾经 提交于 2019-12-03 09:50:16
Python 3.4.2 I am learning asyncio and I use it to continously listen IPC bus, while gbulb listens to the dbus. Some side notes: So I created a function listen_to_ipc_channel_layer that continously listens for incoming messages on the IPC channel and passes the message to a message_handler . I am also listening to SIGTERM and SIGINT. So when I send a SIGTERM to the python process running the code you find at the bottom, the script should terminate gracefully. The problem … I am having is the following warning: got signal 15: exit Task was destroyed but it is pending! task: <Task pending coro=

Getting values from functions that run as asyncio tasks

橙三吉。 提交于 2019-12-03 09:20:55
I was trying the following code: import asyncio @asyncio.coroutine def func_normal(): print("A") yield from asyncio.sleep(5) print("B") return 'saad' @asyncio.coroutine def func_infinite(): i = 0 while i<10: print("--"+str(i)) i = i+1 return('saad2') loop = asyncio.get_event_loop() tasks = [ asyncio.async(func_normal()), asyncio.async(func_infinite())] loop.run_until_complete(asyncio.wait(tasks)) loop.close() I can't figure out how to get values in variables from these functions. I can't do this: asyncio.async(a = func_infinite()) as this would make this a keyword argument. How do I go about

No module named utils error on compiling py file

偶尔善良 提交于 2019-12-03 07:30:26
I'm trying to run a .py file through the command prompt using the command "python filename.py". I've already set the environment variables for python after I installed it, so I don't get any error when I type python. The file I'm running imports a few directories, all of which are preexistent in the same directory as the file I'm running, apart from the file web.py, which I can't seem to locate in the directory, so I'm assuming it's somewhere inside the python package, I have downloaded. But, I couldn't find it there either, so would I need to install an extension for python for the web.py

How to get an input from user in Pygame and save it as a variable? [duplicate]

情到浓时终转凉″ 提交于 2019-12-03 03:33:09
This question already has an answer here : How to get text input from user in Pygame? (1 answer) My idea is I want to take some input from user in the game like name of user, then I want to put it on the screen.Maybe before starting the game or middle of the game, it matter. I tried InputBox etc. but it's not working actually, I tried some of modules like it but none of working, some of them just typing my text on the screen thats all, what I want is I want to take that input and put some places on the pygame screen. So I have to save that input as a variable .Is there any possible way to do