Before installing the package, I read the code and I got a question.
There is double dot in the code when the code calls a module, the module is tools.
What is the double dot in python?
The code wrote from ..tools import *.
You can find it here, https://github.com/synergetics/spectrum/blob/master/src/conventional/cum2x.py
The code is computing the bispectrum.
And do you know the other code analysing a wave interaction for python such as HOSA in MATLAB?
In python, The . is just accessing an attribute. The attribute could be a class, an instance, a method/function, etc and The .. is just specify an relative address in Linux environment. It means go to ../tools folder and import everything inside it.
Related
I am new to python and wxpython, I am making a automated tool using python and for user interface wxpython and i use shell script.shell script can be called from the python. but now I am facing problem with the spinctrl value. whenever that spinctrl value changes it have to send that value into one txt.exe file which is written in BASH .{ if we run txt.exe file in command line it will ask for number then it will accept that value whenever we press enter}. but i am not able to understand that how to send value from spinctrl to txt.exe whenever i press "ok" button in GUI. please share your thoughts and knowledge.
Thank you
To call an executable in Python, you need to look at Python's subprocess module: http://docs.python.org/2/library/subprocess.html
If your exe doesn't accept arguments, then it won't work. If you created the exe yourself using something like PyInstaller or py2Exe, then you need to make it so your app can accept arguments. The simplest way is using sys.argv, but there are also the optparse and argparse libraries in Python as well.
I do not get a good feeling about your concept. It is hard to say, but I suspect you would benefit from talking with someone experienced about what you are trying to achieve and how it could best be done.
However, to get you started down your current path, I think you should take a look at wxExecute ( http://docs.wxwidgets.org/2.8/wx_processfunctions.html#wxexecute ). This will allow you to run your txt.exe utility from inside your GUI.
wxExecute is a wxWidgets utility. If you are working in python then there will be a more direct way to do this using a python utility - some-one else will have to advise on that. I suggest you edit your question for clarity so a python expert can help you.
As part of my code, I want to write a python method which when called, creates an executable file. (Another script that I can execute with python's interpreter is also fine).
This final script is almost fixed, except for a few input objects that only my method knows about, and which are necessary for the final executable to work (a dictionary for example). How can I link these objects to the final executable?
This sounds like a work for some templating engine. Jinja for example.
You can also use pickle to serialize/deserialize (save/load) the data which the other executables would use.
I am writing a game engine and I'd like it to have Python scripting as well as support for mods using PhysFS.
My game data is stored something like this:
/
native
scripts
sprites
...
mods
mymodname
scripts
What I want is for the mod scripts to be able to 'import' the native scripts as if they were in the same directory. Is something like that possible using PhysFS?
You could create a symbolic link so that you can link those files/folders are in a higher directory, with PhysFS you can do:
PHYSFS_permitSymbolicLinks()
Then have PhysFS follow your symbolic links, hope this help :-)
EDIT: What I would do is symbolically link /mods/scripts to /native/mods-scripts so that /native/scripts can call mods-scripts (which actually points to /mods/scripts)
[I am the same person who asked the question.]
The solution I used eventually was to modify Python's sys.path when my program starts. This does not pollute the game's data directories with symbolic links and is overall much cleaner.
I'm trying to embed the Python interpreter and need to customize the way the Python standard library is loaded. Our library will be loaded from the same directory as the executable, not from prefix/lib/.
We have been successful in making this work by manually modifying sys.path after calling Py_Initialize(), however, this generates a warning because Py_Initialize is looking for site.py in ./lib/, and it's not present until after Py_Initialize has been called and we have updated sys.path.
The Python c-api docs hint that it's possible to override Py_GetPrefix() and Py_GetPath(), but give no indication of how. Does anyone know how I would go about overriding them?
You could set Py_NoSiteFlag = 1, call PyInitialize and import site.py yourself as needed.
Have you considered using putenv to adjust PYTHONPATH before calling Py_Initialize?
I see it was asked long ago, but I've just hit the same problem. Py_NoSiteFlag will help with the site module, but generally it's better to rewrite Modules/getpath.c; Python docs officially recommend this for “[a]n application that requires total control.” Python does import some modules during initialization (the one that hit me was encodings), so, unless you don't want them or have embedded them too, the module search path has to be ready before you call Py_Initialize().
From what I understand Py_GetPath merely returns module search path; Py_GetProgramFullPath is self-describing; and Py_GetPrefix and Py_GetExecPrefix are not used by anyone, except some mysterious “ILU”.
The following functions can be called before calling Py_Initialize():
Py_SetProgramName()
Py_SetPythonHome()
Py_SetPath()
All of these affect the way Python finds modules. I recommend reading the documentation on these functions and playing around with them.
I have the following python 3 file:
import base64
import xxx
str = xxx.GetString()
str2 = base64.b64encode(str.encode())
str3 = str2.decode()
print str3
xxx is a module exported by some C++ code. This script does not work because calling Py_InitModule on this script returns NULL. The weird thing is if I create a stub xxx.py in the same directory
def GetString() :
return "test"
and run the original script under python.exe, it works and outputs the base64 string. My question is why doesn't it like the return value of xxx.GetString? In the C++ code, it returns a string object. I hope I have explained my question well enough... this is a strange error.
I know everybody says this...but:
Boost has an awesome library for exposing classes to python and getting data to and fro. If you're having problems, and looking for alternatives is an option I'd highly recommend the boost python library of the C interface. I've used them both, boost wins hands down imo.
Py_InitModule() is for initializing extension modules written in C, which is not what you are looking for here. If you want to import a module from C, there is a wealth of functions available in the C API: http://docs.python.org/c-api/import.html
But if your aim is really to run a script rather than import a module, you could also use one of the PyRun_XXX() functions described here: http://docs.python.org/c-api/veryhigh.html
Er... You have to investigate why Py_InitModule returns NULL. Posting the Python code using that module won't help.