Hot answers tagged

4

You're not actually running a bash command. What you're doing is running an executable directly and passing it arguments. Try the following script to see what is happening: import subprocess p = subprocess.Popen(["echo", "a", "b", "|", "rev"], stdout=subprocess.PIPE) print p.communicate() The output will be: ('a b | rev\n', None) There's no ...


4

If you are maintaining the program, then make it store the history. In Python, use the readline library and make it store a history file. If you don't want to modify the program, you can use a wrapper such as rlwrap. rlwrap -H ~/.myprogram.history myprogram


3

You should store your information in a file, for which the location adheres to the XDG Base Directory Specification. As your material is data and not config you should try if the environment variable XDG_DATA_HOME exists and create a file or a utility specific subdirectory under that, where you store the file. If that environment variable does not exists, ...


3

For this sort of thing, you want to use a configuration file of some sort. Usually a dotfile in the user's home directory will suffice for this sort of thing.


3

To make something like this easily executable, add this as the first line of the python script: #! /usr/bin/python and the file itself should be executable; that is, the x bits must be set, chmod +x fit_locus.py. Since the script is in the amended PATH, users can just enter the name. For simplicity, you can remove the '.py' so users only need to type ...


2

If you look through the formal documentation of the python JSON library you see that the invocation of json.tool should be python -mjson.tool. This indicates that the program in the file tool.py under the json directory of your python installation, or that it is in the file __init__.py in the tool directory under json in your python installation. The file ...


1

To force a refresh of the resolve table, you can run this (on linux): import ctypes libc = ctypes.cdll.LoadLibrary('libc.so.6') res_init = libc.__res_init res_init()


1

There are of course two possibilities: decrease the permissions of the files to a level the user can access increase the permissions the modifying app is having regarding 1) You can try to add additional rights via ACLs (I would heavily discourage changing the UNIX permissions, lots of programs have expectations and they will be changed with the next ...


1

Solution is to run the program itself as root, thereby having permission to files in /etc.


1

Try that: python -m HTTPSimpleServer & watch -n


1

python -m HTTPSimpleServer & # Your Python process will now be in the background serverpid="$!" # Capture its PID so that you can kill it later. watch -n /path/to/AwesomeTestCommand Arg1 Arg2 # Some time later... kill "$serverpid" # Make your Python process go away


1

What you should do is install Django in a virtualenv and not directly in your python installation (2.6 nor 3.5). Where you install virtualenv is not important (it probably goes into the 2.6 install): pip install virtualenv now create a 3.5 virtualenv by doing: virtualenv -p $(which python3.5) /opt/django (adapt the /opt/django to your needs), and then ...


1

python2 and python3 are incompatible with each other, and a lot of the software only work with python2. So, apt-get does not overwrite python2 when you install python3. You should call Python3 with python3 command and use #!/usr/bin/python3 as the shebang in your scripts.


1

Here is one bash solution as well : declare -a a=(1999 2000 2001) url='/test/test' for i in "${a[@]}" ; do echo "$url" | sed "s:/:/$i/:2"; done


1

You specify only one "URL" the following Python program support a list of them: urls = [ '/test/test', ] years = [1999, 2000, 2001] for url in urls: for year in years: spliturl = url.split('/') spliturl.insert(2, str(year)) print('/'.join(spliturl)) The trick is to insert the year at the second position, the first ...



Only top voted, non community-wiki answers of a minimum length are eligible