python-module

Python imports across modules and global variables

邮差的信 提交于 2020-01-28 09:44:34
问题 I have a question which seems to be rather fundamental but I can't seem to find any help on this anywhere. file_a.py >> from xyz import XYZ class A: . . . file_b.py >> import file_a from file_a import A class B(A): def __init__(self): A.__init__(self) def someMethod(self): XYZ.doSomething() XYZ.doSomething() fails saying NameError: name 'XYZ' is not defined Even standard imports like 'import sys' done from file_a does not seem to render it usable in file_b. I assumed that should work. Is my

Python imports across modules and global variables

青春壹個敷衍的年華 提交于 2020-01-28 09:40:23
问题 I have a question which seems to be rather fundamental but I can't seem to find any help on this anywhere. file_a.py >> from xyz import XYZ class A: . . . file_b.py >> import file_a from file_a import A class B(A): def __init__(self): A.__init__(self) def someMethod(self): XYZ.doSomething() XYZ.doSomething() fails saying NameError: name 'XYZ' is not defined Even standard imports like 'import sys' done from file_a does not seem to render it usable in file_b. I assumed that should work. Is my

Python - fails importing package

喜夏-厌秋 提交于 2020-01-23 17:18:47
问题 I have trouble importing package. My file structure is like this: filelib/ __init__.py converters/ __init__.py cmp2locus.py modelmaker/ __init__.py command_file.py In module command_file.py I have a class named CommandFile which i want to call in the cmp2locus.py module. I have tried the following in cmp2locus.py module: import filelib.modelmaker.command_file import modelmaker.command_file from filelib.modelmaker.command_file import CommandFile All these options return ImportError: No modules

Importing modules: __main__ vs import as module

*爱你&永不变心* 提交于 2020-01-18 04:43:16
问题 To preface, I think I may have figured out how to get this code working (based on Changing module variables after import), but my question is really about why the following behavior occurs so I can understand what to not do in the future. I have three files. The first is mod1.py: # mod1.py import mod2 var1A = None def func1A(): global var1 var1 = 'A' mod2.func2() def func1B(): global var1 print var1 if __name__ == '__main__': func1A() Next I have mod2.py: # mod2.py import mod1 def func2():

Numerous “ConnectionRefusedError: [WinError 10061]” in Python requests

人走茶凉 提交于 2020-01-15 03:51:06
问题 So I know that is a lot of code to look at down below, but I'm absolutely stumped because I've never had such an issue when using python. I was hopeful to use the requests module to help me speed up some of my web based activities for work. I downloaded the zipball per the requests of the developers and ran "setup.py" to install it into the "site-packages" directory. I've verified that all the content is indeed where it should be, and theoretically I should be able to import it and then use

Python 3.5 vs Python 2.7: Modules importing submodules

限于喜欢 提交于 2020-01-11 05:09:05
问题 I have been googling this for the past hours and can't find an equivalent question anywhere. Also the documentation for 2.7 and 3.5 seem identical, so I don't think this behavior is documented. Here is my directory structure: project -- project.py -- api -- __init__.py -- subapi -- __init__.py contents of project/project.py : import api contents of project/api/__init__.py : import subapi If I execute python project.py (using python 2.7) from inside the projects folder, it returns without an

Trouble Setting Up MySQLdb Module

走远了吗. 提交于 2020-01-10 11:45:56
问题 I'm pulling my hair out over here trying to set up MySQLdb on my Mac in order to connect to a remote MySQL server. I have installed the latest C MySQL client libraries I have installed XCode 4 I did naively try to install the module before installing XCode or the client libraries I am attempting to set up the module by running the following commands in terminal: $ sudo python setup.py build $ sudo python setup.py install Both of these commands fail with similar error messages. Here is the

How does python find a module file if the import statement only contains the filename?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-08 16:53:15
问题 Everywhere I see Python code importing modules using import sys or import mymodule How does the interpreter find the correct file if no directory or path is provided? 回答1: http://docs.python.org/3/tutorial/modules.html#the-module-search-path 6.1.2. The Module Search Path When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path . sys

Importing deeply nested modules in Python

旧巷老猫 提交于 2020-01-05 03:51:07
问题 Consider the following case in Python 3.6: basepackage |---__init__.py |---package |---__init__.py |---subpackage |---__init__.py |---module.py Important detail : inside basepackage.package.__init__.py there's: from basepackage.package.subpackage.module import AClass as AliasedClass Now, let's say inside basepackage.package.subpackage.module.py we want to use: import basepackage.package.subpackage.module as aliased_module [1] The result is: AttributeError: module 'basepackage' has no

When importing a module without null bytes I get ValueError: source code string cannot contain null bytes

廉价感情. 提交于 2020-01-04 05:25:47
问题 Python isn't importing modules! marketing ├───__init__.py ├───analyzation\ │ ├───__init__.py │ ├───analyzer.py ├───api\ ├───test\ │ ├───test_res\ (not important) │ ├───__init__.py │ ├───test_analyzer.py Above is my folder structure. So, in analyzer.py I have a class DataSet and nothing else other than some imports from pandas and an import in a method import random . In test_analyzer.py I have a class that subclasses unittest.TestCase . This script tries to test the following class being