Questions tagged [python-module]

A module is a file containing Python definitions and statements.

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.

2038 questions
46
votes
7 answers

Python unittest - Ran 0 tests in 0.000s

So I want to do this code Kata for practice. I want to implement the kata with tdd in separate files: The algorithm: # stringcalculator.py def Add(string): return 1 and the tests: # stringcalculator.spec.py from stringcalculator import…
MattSom
  • 2,097
  • 5
  • 31
  • 53
42
votes
9 answers

Is there a Python module to open SPSS files?

Is there a module for Python to open IBM SPSS (i.e. .sav) files? It would be great if there's something up-to-date which doesn't require any additional dll files/libraries.
Lamps1829
  • 2,231
  • 3
  • 24
  • 32
41
votes
9 answers

Module Not found during import in Jupyter Notebook

I have the following package (and working directory): WorkingDirectory-- |--MyPackage-- | |--__init__.py | |--module1.py | |--module2.py …
Ryan
  • 1,040
  • 3
  • 16
  • 25
40
votes
6 answers

Is it possible to list all functions in a module?

I defined a .py file in this format: foo.py def foo1(): pass def foo2(): pass def foo3(): pass I import it from another file: main.py from foo import * # or import foo Is it possible list all functions name, e.g. ["foo1", "foo2", "foo3"]? Thanks…
user478514
  • 3,859
  • 10
  • 33
  • 42
40
votes
9 answers

python module for nslookup

Is there a python-module that's doing the same stuff as nslookup does? I am planning to use nslookup on digging some information regarding the domain of a URL to be scrapped. I know I can use os.sys to call nslookup but I am just wondering if there…
jaysonpryde
  • 2,733
  • 11
  • 44
  • 61
39
votes
11 answers

Recursive version of 'reload'

When I'm developing Python code, I usually test it in an ad-hoc way in the interpreter. I'll import some_module, test it, find a bug, fix the bug and save, and then use the built-in reload function to reload(some_module) and test again. However,…
Mark Amery
  • 143,130
  • 81
  • 406
  • 459
36
votes
12 answers

What do I need to read Microsoft Access databases using Python?

How can I access Microsoft Access databases in Python? With SQL? I'd prefere a solution that works with Linux, but I could also settle for Windows. I only require read access.
Georg Schölly
  • 124,188
  • 49
  • 220
  • 267
36
votes
6 answers

How to debug a Python module run with python -m from the command line?

I know that a Python script can be debugged from the command line with python -m pdb my_script.py if my_script.py is a script intended to be run with python my_script.py. However, a python module my_module.py should be run with python -m my_module.…
Alexey
  • 3,843
  • 6
  • 30
  • 44
34
votes
5 answers

Python: replacing a function within a class of a module

I'm trying to replace a function defined within a class in order to modify its function (as in inner workings) without changing the actual code. I've never done this before, and, hence, am having some problems while replacing it. Changing the code…
Cody Chung
  • 629
  • 1
  • 6
  • 15
34
votes
1 answer

__init__.py can't find local modules

Borrowing a simplified example at http://pythoncentral.io/how-to-create-a-python-package/ I have an analogous file structure as follows, where Mammals.py and Birds.py define classes with the same names: Project/ Animals/ __init__.py …
Darren McAffee
  • 645
  • 1
  • 6
  • 10
34
votes
6 answers

How do I extend a python module? Adding new functionality to the `python-twitter` package

What are the best practices for extending an existing Python module – in this case, I want to extend the python-twitter package by adding new methods to the base API class. I've looked at tweepy, and I like that as well; I just find python-twitter…
user319045
  • 665
  • 3
  • 7
  • 12
34
votes
10 answers

Installing nose using pip, but bash doesn't recognize command on mac

I'm trying to install nose on my computer for the Learn Python the Hard Way tutorial, but can't seem to get it to work. I'm using pip to install: $ pip install nose And I get back: Requirement already satisfied (use --upgrade to upgrade): nose in…
Zubin
  • 393
  • 1
  • 3
  • 7
33
votes
8 answers

Python - ModuleNotFoundError: No module named

I'm new in Python and I'm having the following error with this simple example: This is my project structure: python_project . ├── lib │   ├── __init__.py │   └── my_custom_lib.py └── src ├── __init__.py └── main.py And this is the error…
Nicolas
  • 331
  • 1
  • 3
  • 5
33
votes
3 answers

Python calling a module that uses argparser

This is probably a silly question, but I have a python script that current takes in a bunch of arguments using argparser and I would like to load this script as a module in another python script, which is fine. But I am not sure how to call the…
Pectus Excavatum
  • 3,593
  • 16
  • 47
  • 68
32
votes
7 answers

Import a module with parameter in python

Is it possible to import a module with some parameter in python ? All I mean by parameter is that there exists a variable in the module which is not initialized in that module, still I am using that variable in that module. In short, I want behavior…
turing
  • 577
  • 1
  • 4
  • 12