top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Python: function inclusion problem

+2 votes
580 views

I defined function Fatalln in "mydef.py" and it works fine if I call it from "mydef.py", but when I try to call it from "test.py" in the same folder:

import mydef
...
Fatalln "my test"

i have NameError: name 'Fatalln' is not defined, I also tried include('mydef.py') with the same result...
What is the right syntax?

posted Feb 10, 2015 by Sidharth

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

Preferred:

import mydef
mydef.Fatalln("my test")

Also acceptable:

from mydef import Fatalln
Fatalln("my test")
answer Feb 11, 2015 by Tarun Singhal
+1 vote

Try

 import mydef
 mydef.Fatalin("my test")

or

 from mydef import Fatalin
 Fatalin("my test")
answer Feb 11, 2015 by Salil Agrawal
Similar Questions
+2 votes

What's the problem with Python 3.x? It was first released in 2008, but web hosting companies still seem to offer Python 2.x rather.

For example, Google App Engine only offers Python 2.7. What's wrong?...

+1 vote

I remember to avoiding to confusing compiler for header, use

// in my include file
#define MYHEADER_H
// and in others code use:
#ifndef MYHEADER_H
#include blahblah

Unfortunately, I prevent to same error, double import to python, but I don't know how to solve, Please help.

0 votes

I have a hierarchy of classes (SubA, SubAB, SubB, ..., SubBCA, SubC,...), each of which is inheriting from a chain of superclasses with a common baseclass(Sup) on top. (So far, no problem)

Now, I want to create instances of the correct subclasstype as decided by the common baseclass, like this:

i = Sup(args_allowing_the_baseclass_to_deduce_correct_subclass)

where i can be of any class except Sup itself (as decided by Sup)

Now, the problem:

How to design the __new__() and __init__() methods for the various classes in order to achieve what I want?

0 votes

im trying to do a simple socket test program for a school project using the socket module, but im having difficulty in sending data between the client and host program.

so far all tutorials and examples have used something along the lines of:

 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 host = socket.gethostname()
 port = 12345
 s.connect((host, port))

and received it on the server end with:

 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 host = ''
 port = 12345
 s.bind((host, port))
 s.listen(1)
 conn, addr = s.accept()
 print ('client is at', addr)
 data = conn.recv(5)
 print(data)

it all works fine, except for when i try to use:

 s.send("hello")

to send data between the client and server, i just get this error message:

 Traceback (most recent call last):
 File "C:/Users/xxxxx/Documents/code/chatroom/client3.py", line 9, in 
 s.send("hello")
 TypeError: 'str' does not support the buffer interface

if anyone can either show me what im doing wrong, what this means and what's causing it, or even better how to fix it it would be greatly appreciated

0 votes

This is my first time using pyinstaller. My goal is to build an .app in Mac. The app is basically a GUI written in PySide, and I have about 7 different Python scripts + 1 .png file. The main file calls 4 of the files, and the 4 files will call the rest of the 2 files repeatedly. The .png file is nothing but the window logo. Could someone help me with some diagnosis? I do not know what went wrong. I searched a lot of documentations online, i.e., change spec, add import, ... etc. but my app still doesn't run.FYI, Pyinstaller could generate an app for me, but there are two issues:
1. Icon is not changed for the app.
2. App crashes when opened.

My Python version is 2.7.5 and I am using PyInstaller-2.0. Here is my code for packaging:

python pyinstaller.py --onefile --windowed --name=MyApplication -i ~/Documents/AASource/icon.ico ~/Documents/AASource/Scripts/main_file.pyHere is the spec file:

$ -*- mode: python -*- a = Analysis(['/Users/boxuancui/Documents/AASource/Scripts/main_file.py'], pathex=['/Users/boxuancui/Documents/pyinstaller-2.0'], hiddenimports=[], hookspath=None) pyz = PYZ(a.pure) exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, name=os.path.join('dist', 'MyApplication'), debug=False, strip=None, upx=True, console=False , icon='/Users/boxuancui/Documents/AASource/icon.ico') app = BUNDLE(exe, name=os.path.join('dist', 'MyApplication.app'))Here is part of the crash message:

Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x00000000000054d8

Thanks in advance! Any help will be appreciated!

...