import threading not working python 2.7 [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am trying to use threading in an upcoming project but I can't get it working. I've tried running the 2nd example on http://www.tutorialspoint.com/python/python_multithreading.htm, which I imagine is working code, but I get the error...
Traceback (most recent call last):
File "C:/Python27/threads/threading.py", line 3, in <module>
import threading2
File "C:\Python27\lib\site-packages\threading2\__init__.py", line 49, in <module>
from threading import _active,_DummyThread
File "C:\Python27\threads\threading.py", line 8, in <module>
class myThread (threading2.Thread):
AttributeError: 'module' object has no attribute 'Thread'
Whats going on? It seems like there is no module named threading. I've looked everywhere to find it. Does anyone know where I can find this module and how to install it?

You called your own file threading and now you're importing your own script and that's not what you want. Please do not use the names of existing packages/modules for your own scripts.
When the code in threading2.py tries to import threading, Python first looks for an already-imported module with that name. If that fails, it looks through each location in sys.path for a file named threading.py that it can load. Normally, it will find the one in the standard library. But if you have a file named threading.py in the same location as the script—or if it's the name of the script itself—Python will find that one first, and load it instead.
Also, don't save your own scripts in the folder where Python is installed.

Related

CS50 Pset9 Finance TraceBack, FileNotFoundError, AttributeError [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
Pset9 Finance, please help! When I put my API_Key and run flask, I get these errors that I haven't seen before and don't know how to fix:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/cachelib/file.py", line 219, in delete
os.remove(self._get_filename(key))
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmplxzjvek9/f65da5cfc2b86410e5c673fb6ba2227e'
I have been stuck for the past 2 hours trying to fix this. I tried to ignore them and start the problem set by doing the register part and when I test it I get more issues (AttributeError: 'str' object has no attribute 'get') as you can see. Please help!
enter image description here
enter image description here
enter image description here
As the error message states, request.method is a string, so you can't call the .get() method on it. That method is not defined for strings.
I am not familiar with CS50's problem sets. That being said, it appears that you're trying to access parameters associated with the request on lines 124-126, which is the location of your issue.
For query parameters, use request.args.get('...').
For body parameters, use request.form.get('...').

Pandas can't open a csv file FileNotFoundError [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am having a hard time opening a csv with Pandas. I have tried the example in 'Pandas for Everyone' book, have googled many times and last example was here https://analytics4all.org/2016/05/09/python-read-csv-and-excel-with-pandas/
The python program is in a folder called 'lbcsv' then the csv files are in another folder within that one called csv. I have tried not using full path, placing csv file in same folder as the program, then moving them to another folder in the same directory. Just does not seem to want to open the csv. I have tried without the encoding and sep. Before this I had to uninstall pandas and numpy then reinstall because it was giving an error about numpy. I have got around this before but did not ask the question on here so I have no documentation of how I did so.
import pandas as pd
import numpy
servers = pd.read_csv('C:\\Users\\a089673\\Desktop\\lbcsv\\csv\\server.csv', encoding='utf-8', sep=',')
print(servers.head())
Traceback (most recent call last):
File "C:/Users/a089673/Desktop/lbcsv/pandaslb.py", line 4, in <module>
servers = pd.read_csv('C:\\Users\\a089673\\Desktop\\lbcsv\\csv\\server.csv', encoding='utf-8', sep=',')
FileNotFoundError: File b'C:\\Users\\a089673\\Desktop\\lbcsv\\csv\\server.csv' does not exist
For completeness, \a is an escape character and that is causing issue for you. Using raw string as mentioned in the comments solve this issue.
You can see this clearly if you do repr(file_path) . This is one of the gotchas with Windows. I would suggest using forward slashes for accessing files even in Windows to avoid running into these issues.
Can you try below code
df=pd.read_csv('C:\\\\Users\\\\a089673\\\\Desktop\\\\lbcsv\\\\csv\\\\server.csv')
df
Hope it helps !
Answer was to add the 's' at the end of the file name and to use the \ in the file path.

Why is this simple Python script failing? Python 2.6.6 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Here's the script
#!/usr/bin/python
class LEG(Structure):
_fields_ = [("distance_sm", c_float), ("distance_nm", c_float)]
Here's what I get when I run it.
Traceback (most recent call last):
File "./test.py", line 3, in <module>
class LEG(Structure):
NameError: name 'Structure' is not defined
Yes, brand new to python, thanks for your help
It looks like you're trying to use the Structure type from the ctypes module. You need to import that, as well as c_float and anything else you use from that module:
from ctypes import Structure, c_float

Python help - AttributeError: 'module' object has no attribute 'ArgumentParser' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I need help with something that should be basic. Using the example from Python.org I am encountering the following error
parser = argparse.ArgumentParser(description='Process some integers.')
AttributeError: 'module' object has no attribute 'ArgumentParser'
import argparse
parser = argparse.ArgumentParser()
A print argparse.__ file__ confirmed that it is calling the correct argparse.py file:
File "C:\Python27\lib\argparse.py", line 86, in
Also I made sure there are no nameclashes withother modules. Infact, just removing everything else from the script still calls this error.
Have tried reinstalling python 2.7.9 with no change.
Help this noob please!
It's because your file name is the same as the module name. Rename your file and try again.
so, I had:
from numpy import *
and I changed this to import numpy and it didn't work.
Then I copied all the test verbatim and made a new .py file and saved it out.
Now it works.
thank you Python. I think i'll stick to C!! :S
I think I know what's wrong. It may be unavailable in the release of Python 2.7 that you're using. Try installing Python 2.7.8 or 2.7.9.
When importing modules, python usually first looks for them in your current Path, and only if it can't find them there, it will then look in the other Python-paths (found in sys.path).
Like Daniel Roche said, You obviously named your script "argparse.py" (thinking this would be a good name for an example on how to use argparse, an intuitive and common mistake, I think) and then basically told your script to import itself (how rude).
... And since your script does not have an "ArgumentParser" method defined, this must of course yield an Error.

Retrieve source of web pages by providing file which contains multiple URLs [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to download source of webpages by providing a file which contains a list of their URLs.
For example, I have a file which has following URLs
http://www.adobe.com/support/security/bulletins/apsb09-19.html
http://www.adobe.com/support/security/bulletins/apsb09-20.html
Can I do it using urllib because I want to use python modules not the unix commands (like wget)?
I want read this file and give each URL as input to urlopen or urlretrieve, can anyone tell me how to do that?
Try to break down the issue as best as you can. You've got a text file with each URL listed on its own line. You know that Python's got great support for reading line by line, thanks to open(), and you're probably familiar with urllib or requests, depending on your preference.
So all you need to do is:
Open the file
Read line by line
Use the line as an URL string
Send a request to the URL using urllib or requests
Capture the output and parse it/save it
And you're done!

Categories