I have two classes: a parent class and a container class. The parent class instance has matching container class instance as a weak reference. There is a problem while deep copying the parent instance, the weakref is still linking to the original instance. Here is a minimal example: import weakref from copy import deepcopy class Container: def __init__(self, parent): self.parent = weakref.ref(parent) class Parent: def __init__(self): self.container = Container(self) if __name__ == '__main__': parent1 = Parent() assert(parent1 is parent1.container.parent()) parent2 = deepcopy(parent1) assert
I'm trying to use cx_freeze to build a binary dist for an web application written in Python 3 using the aiohttp package. Basically I did: cxfreeze server.py and got a dist output But when running the ./server binary, I got the following message: File "/usr/local/lib/python3.5/dist-packages/cx_Freeze/initscripts/__startup__.py", line 12, in <module> __import__(name + "__init__") File "/usr/local/lib/python3.5/dist-packages/cx_Freeze/initscripts/Console.py", line 24, in <module> exec(code, m.__dict__) File "server.py", line 1, in <module> File "/usr/local/lib/python3.5/dist-packages/aiohttp/_
I m trying to extract lines from a log file , using that code : with open('fichier.01') as f: content = f.readlines() print (content) but its always makes the error statement Traceback (most recent call last): File "./parsepy", line 4, in <module> content = f.readlines() File "/usr/lib/python3.5/codecs.py", line 321, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 2213: invalid continuation byte how can i fix it ??
The following code just hangs without ever printing anything: import asyncio async def foo(loop): print('foo') loop.stop() loop = asyncio.new_event_loop() asyncio.ensure_future(foo(loop)) loop.run_forever() If I use get_event_loop everything works fine. Is there something I'm doing wrong or have I stumbled upon a bug? I'm using Python 3.5.1.
This is the code I am trying to run: from pexpect import pxssh s = pxssh.pxssh() if not s.login ('myip', 'myusername', 'mypassword'): print ("SSH session failed on login.") print (str(s)) else: print ("SSH session login successful") s.sendline ('ls -l') s.prompt() # match the prompt print (s.before) # print everything before the prompt. s.logout() The error which I am getting on running this is : Traceback (most recent call last): File "test_pexpect.py", line 1, in <module> from pexpect import pxssh File "C:\Python35\lib\site-packages\pexpect\pxssh.py", line 23, in <module> from pexpect import
#!/usr/bin/env python # encoding: utf-8 import tweepy #https://github.com/tweepy/tweepy import json as simplejson #write tweet objects to JSON file = open('tweet.json', 'wb') print ("Writing tweet objects to JSON please wait...") for status in alltweets: json.dump(status._json,file,sort_keys = True,indent = 4) #close the file print ("Done") file.close() if __name__ == '__main__': #pass in the username of the account you want to download get_all_tweets("@AlertZaAfrica") The python compiler says line 54 is wrong. I already defined import json as simplejson. The above area where I defined import
I have a dataframe where I would like to concatenate certain columns. My issue is that the text in these columns may or may not contain duplicate information. I would like to strip out the duplicates in order to retain only the relevant information. For example, if I had a data frame such as: pd.read_csv("animal.csv") animal1 animal2 label 1 cat dog dolphin 19 2 dog cat cat 72 3 pilchard 26 koala 26 4 newt bat 81 bat 81 I want to combine the columns but retain only unique information from each of the strings. You can see that in row 2, 'cat' is contained in both columns 'Animal1' and 'Animal2'
I am trying to install cx_Oracle on my windows PC. I ran following command in command prompt: pip install cx_Oracle This is giving me the following error: Collecting cx-Oracle Could not find a version that satisfies the requirement cx-Oracle (from versions: ) No matching distribution found for cx-Oracle I am using windows 64bit machine and Python 3.5(Anaconda3). Intsalled Oracle vcersion on my PC is Oracle 126.96.36.199.0 and oracle-instantclient version oracle-instantclient-188.8.131.52.0-0 Please let me know what am I missing. Should I downgrade my python version to 3.4? If yes, than how to do it
How to find the number of hours between two dates excluding weekends and certain holidays in Python? BusinessHours package
I'm trying to find a very clean method to calculate the number of hours between two dates excluding weekends and certain holidays. What I found out is that the package BusinessHours (https://pypi.python.org/pypi/BusinessHours/1.01) can do this. However I did not find any instruction on how to use the package (the syntax actually) especially how to input the holidays. I found the original code of the package (https://github.com/dnel/BusinessHours/blob/master/BusinessHours.py) but still not so sure. I guess it could be something like this: date1 = pd.to_datetime('2017-01-01 00:00:00') date2 = pd