I am running Windows 10 with MS Code Python 3.7
I get the following message from my simple code block
Traceback (most recent call last):
File "c:/Users/marke/OneDrive/Desktop/Python Tutorial/json.py", line 1, in
module
import json File "c:\Users\marke\OneDrive\Desktop\Python Tutorial\json.py", line 6, in
jsText = json.loads(FileText) AttributeError: partially initialized module 'json' has no attribute 'loads' (most likely due to
a circular import)
My code
import json
jsFile = open("myjson.json","r")
FileText = jsFile.read
jsText = json.loads(FileText)
When you name your script the name of the module you try to import, python tries to imports your script first, which results in the Error
Related
I am having troubles with making my code running in Python3 (it was in Python2 and I am converting it).
Here is the project structure:
lyrics/__init__.py
lyrics/lyrics.py
./manifold.py
in manifold.py :
import lyrics as lyr
lyr.Domain(label="Points", data=X)
where Domain class is defined in lyrics/lyrics.py:
class Domain(object):
...
When I execute manifold.py with:
./manifold.py
I get this error:
Traceback (most recent call last): File "./manifold.py", line 76, in
Points = lyr.Domain(label="Points", data=X) AttributeError: module 'lyrics' has no attribute 'Domain'
Any idea ?
Thank you
[EDIT]
in lyrics/init.py
from lyrics import *
from . import functions
enter image description here
Hey, i am new in python
i am trying to import shelve module but pycharm say
Traceback (most recent call last):
File "C:\Users\mavic\PycharmProjects\ABS-CH8\shelve.py", line 1, in
import shelve
File "C:\Users\mavic\PycharmProjects\ABS-CH8\shelve.py", line 2, in
namavariale = shelve.open('mydata')
AttributeError: partially initialized module 'shelve' has no attribute 'open' (most likely due to a circular import)
i am trying to import shelve module not shelve.py, what is the solution?
My code is:
import re
s="An apple in a day."
print(re.search("in",s))
Error:
C:\Users\DELL\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/DELL/AppData/Local/Programs/Python/Python38-32/Lib/encodings/re.py
Traceback (most recent call last):
File "C:/Users/DELL/AppData/Local/Programs/Python/Python38-32/Lib/encodings/re.py", line 1, in <module>
import re
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\Lib\encodings\re.py", line 3, in <module>
re.search("is",s)
AttributeError: partially initialized module 're' has no attribute 'search' (most likely due to a circular import)
Process finished with exit code 1
You name your file re.py so python confused which one to use when you call import re: your file or regexp library.
Try to rename your file to something else and not to choose other library names.
I need to create a simple script for fixing indentation in python scripts of the repository. I found fix_multiple_files in autopep8 module:
import autopep8
autopep8.fix_multiple_files('/home/playrix/work/ci-teamcity/scripts/', options={'recursive': 1})
I'm getting this every time I run the script:
Traceback (most recent call last):
File "/home/playrix/work/ci-teamcity/scripts/1.py", line 4, in <module>
autopep8.fix_multiple_files('/home/playrix/work/ci-teamcity/scripts/', options='')
File "/home/playrix/.local/lib/python2.7/site-packages/autopep8.py", line 3897, in fix_multiple_files
filenames = find_files(filenames, options.recursive, options.exclude)
AttributeError: 'str' object has no attribute 'recursive'
How correctly noticed johnsharpe it was argparse.Namespace. And the best way to get it was:
opt = autopep8.parse_args(arguments=['recursive', '--in-place', '--aggressive'])
I am trying to extract URLs from CSS stylesheet using cssutils.getUrls('stylesheet.css')
However when I run the code I get an error complaining about 'getUrls' see below. I am running on python 3.6
import cssutils
cssutils.getUrls('http://4nprofessionals.com/css/style.css')
Traceback (most recent call last):
File "", line 1, in
cssutils.getUrls('http://4nprofessionals.com/css/style.css')
AttributeError: module 'cssutils' has no attribute 'getUrls'