text stringlengths 200 200k | source stringclasses 2
values |
|---|---|
# Python - time.clock() vs. time.time() - accuracy?
## Question
Which is better to use for timing in Python? time.clock() or time.time()? Which one provides more accuracy?
for example:
start = time.clock()
... do something
elapsed = (time.clock() - start)
vs.
start = time.time()
... do something
elapsed = (time.t... | stackoverflow-qa |
# Python - time.clock() vs. time.time() - accuracy?
## Question
Which is better to use for timing in Python? time.clock() or time.time()? Which one provides more accuracy?
for example:
start = time.clock()
... do something
elapsed = (time.clock() - start)
vs.
start = time.time()
... do something
elapsed = (time.t... | stackoverflow-qa |
# Python - time.clock() vs. time.time() - accuracy?
## Question
Which is better to use for timing in Python? time.clock() or time.time()? Which one provides more accuracy?
for example:
start = time.clock()
... do something
elapsed = (time.clock() - start)
vs.
start = time.time()
... do something
elapsed = (time.t... | stackoverflow-qa |
# Python - time.clock() vs. time.time() - accuracy?
## Question
Which is better to use for timing in Python? time.clock() or time.time()? Which one provides more accuracy?
for example:
start = time.clock()
... do something
elapsed = (time.clock() - start)
vs.
start = time.time()
... do something
elapsed = (time.t... | stackoverflow-qa |
# Python - time.clock() vs. time.time() - accuracy?
## Question
Which is better to use for timing in Python? time.clock() or time.time()? Which one provides more accuracy?
for example:
start = time.clock()
... do something
elapsed = (time.clock() - start)
vs.
start = time.time()
... do something
elapsed = (time.t... | stackoverflow-qa |
# Python - time.clock() vs. time.time() - accuracy?
## Question
Which is better to use for timing in Python? time.clock() or time.time()? Which one provides more accuracy?
for example:
start = time.clock()
... do something
elapsed = (time.clock() - start)
vs.
start = time.time()
... do something
elapsed = (time.t... | stackoverflow-qa |
# Search for host with MAC-address using Python
## Question
I'd like to search for a given MAC address on my network, all from within a Python script. I already have a map of all the active IP addresses in the network but I cannot figure out how to glean the MAC address. Any ideas?
## Answer
I don't think there is ... | stackoverflow-qa |
# Search for host with MAC-address using Python
## Question
I'd like to search for a given MAC address on my network, all from within a Python script. I already have a map of all the active IP addresses in the network but I cannot figure out how to glean the MAC address. Any ideas?
## Answer
You need ARP. Python's ... | stackoverflow-qa |
# Search for host with MAC-address using Python
## Question
I'd like to search for a given MAC address on my network, all from within a Python script. I already have a map of all the active IP addresses in the network but I cannot figure out how to glean the MAC address. Any ideas?
## Answer
If you want a pure Pyth... | stackoverflow-qa |
# Search for host with MAC-address using Python
## Question
I'd like to search for a given MAC address on my network, all from within a Python script. I already have a map of all the active IP addresses in the network but I cannot figure out how to glean the MAC address. Any ideas?
## Answer
It seems that there is ... | stackoverflow-qa |
# Search for host with MAC-address using Python
## Question
I'd like to search for a given MAC address on my network, all from within a Python script. I already have a map of all the active IP addresses in the network but I cannot figure out how to glean the MAC address. Any ideas?
## Answer
This article, "Send han... | stackoverflow-qa |
# How to best implement simple crash / error reporting?
## Question
What would be the best way to implement a simple crash / error reporting mechanism?
Details: my app is cross-platform (mac/windows/linux) and written in Python, so I just need something that will send me a small amount of text, e.g. just a timestamp... | stackoverflow-qa |
# How to best implement simple crash / error reporting?
## Question
What would be the best way to implement a simple crash / error reporting mechanism?
Details: my app is cross-platform (mac/windows/linux) and written in Python, so I just need something that will send me a small amount of text, e.g. just a timestamp... | stackoverflow-qa |
# How to best implement simple crash / error reporting?
## Question
What would be the best way to implement a simple crash / error reporting mechanism?
Details: my app is cross-platform (mac/windows/linux) and written in Python, so I just need something that will send me a small amount of text, e.g. just a timestamp... | stackoverflow-qa |
# How to best implement simple crash / error reporting?
## Question
What would be the best way to implement a simple crash / error reporting mechanism?
Details: my app is cross-platform (mac/windows/linux) and written in Python, so I just need something that will send me a small amount of text, e.g. just a timestamp... | stackoverflow-qa |
# What are the pros and cons of the various Python implementations?
## Question
I am relatively new to Python, and I have always used the standard cpython (v2.5) implementation.
I've been wondering about the other implementations though, particularly Jython and IronPython. What makes them better? What makes them ... | stackoverflow-qa |
# What are the pros and cons of the various Python implementations?
## Question
I am relatively new to Python, and I have always used the standard cpython (v2.5) implementation.
I've been wondering about the other implementations though, particularly Jython and IronPython. What makes them better? What makes them ... | stackoverflow-qa |
# What are the pros and cons of the various Python implementations?
## Question
I am relatively new to Python, and I have always used the standard cpython (v2.5) implementation.
I've been wondering about the other implementations though, particularly Jython and IronPython. What makes them better? What makes them ... | stackoverflow-qa |
# What are the pros and cons of the various Python implementations?
## Question
I am relatively new to Python, and I have always used the standard cpython (v2.5) implementation.
I've been wondering about the other implementations though, particularly Jython and IronPython. What makes them better? What makes them ... | stackoverflow-qa |
# What are the pros and cons of the various Python implementations?
## Question
I am relatively new to Python, and I have always used the standard cpython (v2.5) implementation.
I've been wondering about the other implementations though, particularly Jython and IronPython. What makes them better? What makes them ... | stackoverflow-qa |
# What are the pros and cons of the various Python implementations?
## Question
I am relatively new to Python, and I have always used the standard cpython (v2.5) implementation.
I've been wondering about the other implementations though, particularly Jython and IronPython. What makes them better? What makes them ... | stackoverflow-qa |
# Get list of XML attribute values in Python
## Question
I need to get a list of attribute values from child elements in Python.
It's easiest to explain with an example.
Given some XML like this:
<elements>
<parent name="CategoryA">
<child value="a1"/>
<child value="a2"/>
<child value="a... | stackoverflow-qa |
# Get list of XML attribute values in Python
## Question
I need to get a list of attribute values from child elements in Python.
It's easiest to explain with an example.
Given some XML like this:
<elements>
<parent name="CategoryA">
<child value="a1"/>
<child value="a2"/>
<child value="a... | stackoverflow-qa |
# Get list of XML attribute values in Python
## Question
I need to get a list of attribute values from child elements in Python.
It's easiest to explain with an example.
Given some XML like this:
<elements>
<parent name="CategoryA">
<child value="a1"/>
<child value="a2"/>
<child value="a... | stackoverflow-qa |
# Get list of XML attribute values in Python
## Question
I need to get a list of attribute values from child elements in Python.
It's easiest to explain with an example.
Given some XML like this:
<elements>
<parent name="CategoryA">
<child value="a1"/>
<child value="a2"/>
<child value="a... | stackoverflow-qa |
# Get list of XML attribute values in Python
## Question
I need to get a list of attribute values from child elements in Python.
It's easiest to explain with an example.
Given some XML like this:
<elements>
<parent name="CategoryA">
<child value="a1"/>
<child value="a2"/>
<child value="a... | stackoverflow-qa |
# Get list of XML attribute values in Python
## Question
I need to get a list of attribute values from child elements in Python.
It's easiest to explain with an example.
Given some XML like this:
<elements>
<parent name="CategoryA">
<child value="a1"/>
<child value="a2"/>
<child value="a... | stackoverflow-qa |
# If it is decided that our system needs an overhaul, what is the best way to go about it?
## Question
We are mainting a web application that is built on Classic ASP using VBScript as the primary language. We are in agreement that our backend (framework if you will) is out dated and doesn't provide us with the proper ... | stackoverflow-qa |
# If it is decided that our system needs an overhaul, what is the best way to go about it?
## Question
We are mainting a web application that is built on Classic ASP using VBScript as the primary language. We are in agreement that our backend (framework if you will) is out dated and doesn't provide us with the proper ... | stackoverflow-qa |
# If it is decided that our system needs an overhaul, what is the best way to go about it?
## Question
We are mainting a web application that is built on Classic ASP using VBScript as the primary language. We are in agreement that our backend (framework if you will) is out dated and doesn't provide us with the proper ... | stackoverflow-qa |
# If it is decided that our system needs an overhaul, what is the best way to go about it?
## Question
We are mainting a web application that is built on Classic ASP using VBScript as the primary language. We are in agreement that our backend (framework if you will) is out dated and doesn't provide us with the proper ... | stackoverflow-qa |
# If it is decided that our system needs an overhaul, what is the best way to go about it?
## Question
We are mainting a web application that is built on Classic ASP using VBScript as the primary language. We are in agreement that our backend (framework if you will) is out dated and doesn't provide us with the proper ... | stackoverflow-qa |
# Setting Environment Variables for Mercurial Hook
## Question
I am trying to call a shell script that sets a bunch of environment variables on our server from a mercurial hook. The shell script gets called fine when a new changegroup comes in, but the environment variables aren't carrying over past the call to the sh... | stackoverflow-qa |
# How do you configure Django for simple development and deployment?
## Question
I tend to use SQLite when doing Django
development, but on a live server something more robust is
often needed (MySQL/PostgreSQL, for example).
Invariably, there are other changes to make to the Django
settings as well: different logging ... | stackoverflow-qa |
# How do you configure Django for simple development and deployment?
## Question
I tend to use SQLite when doing Django
development, but on a live server something more robust is
often needed (MySQL/PostgreSQL, for example).
Invariably, there are other changes to make to the Django
settings as well: different logging ... | stackoverflow-qa |
# How do you configure Django for simple development and deployment?
## Question
I tend to use SQLite when doing Django
development, but on a live server something more robust is
often needed (MySQL/PostgreSQL, for example).
Invariably, there are other changes to make to the Django
settings as well: different logging ... | stackoverflow-qa |
# How do you configure Django for simple development and deployment?
## Question
I tend to use SQLite when doing Django
development, but on a live server something more robust is
often needed (MySQL/PostgreSQL, for example).
Invariably, there are other changes to make to the Django
settings as well: different logging ... | stackoverflow-qa |
# How do you configure Django for simple development and deployment?
## Question
I tend to use SQLite when doing Django
development, but on a live server something more robust is
often needed (MySQL/PostgreSQL, for example).
Invariably, there are other changes to make to the Django
settings as well: different logging ... | stackoverflow-qa |
# How do you configure Django for simple development and deployment?
## Question
I tend to use SQLite when doing Django
development, but on a live server something more robust is
often needed (MySQL/PostgreSQL, for example).
Invariably, there are other changes to make to the Django
settings as well: different logging ... | stackoverflow-qa |
# How do you configure Django for simple development and deployment?
## Question
I tend to use SQLite when doing Django
development, but on a live server something more robust is
often needed (MySQL/PostgreSQL, for example).
Invariably, there are other changes to make to the Django
settings as well: different logging ... | stackoverflow-qa |
# How do you configure Django for simple development and deployment?
## Question
I tend to use SQLite when doing Django
development, but on a live server something more robust is
often needed (MySQL/PostgreSQL, for example).
Invariably, there are other changes to make to the Django
settings as well: different logging ... | stackoverflow-qa |
# How do I unit test an __init__() method of a python class with assertRaises()?
## Question
I have a class:
class MyClass:
def __init__(self, foo):
if foo != 1:
raise Error("foo is not equal to 1!")
and a unit test that is supposed to make sure the incorrect arg passed to the constructor properly raise... | stackoverflow-qa |
# How do I unit test an __init__() method of a python class with assertRaises()?
## Question
I have a class:
class MyClass:
def __init__(self, foo):
if foo != 1:
raise Error("foo is not equal to 1!")
and a unit test that is supposed to make sure the incorrect arg passed to the constructor properly raise... | stackoverflow-qa |
# In Python, how do you take tokenized input such as with the C++?
## Question
In C++, I can have take input like this:
cin >> a >> b >> c;
And a can be int, b can be float, and c can be whatever... How do I do the same in python?
input() and raw_input(), the way I'm using them, don't seem to be giving me the des... | stackoverflow-qa |
# In Python, how do you take tokenized input such as with the C++?
## Question
In C++, I can have take input like this:
cin >> a >> b >> c;
And a can be int, b can be float, and c can be whatever... How do I do the same in python?
input() and raw_input(), the way I'm using them, don't seem to be giving me the des... | stackoverflow-qa |
# How do I split a string into a list?
## Question
If I have this string:
2+24*48/32
what is the most efficient approach for creating this list:
['2', '+', '24', '*', '48', '/', '32']
## Answer
Regular expressions:
>>> import re
>>> splitter = re.compile(r'([+*/])')
>>> splitter.split("2+24*48/32")
You c... | stackoverflow-qa |
# How do I split a string into a list?
## Question
If I have this string:
2+24*48/32
what is the most efficient approach for creating this list:
['2', '+', '24', '*', '48', '/', '32']
## Answer
s = "2+24*48/32"
p = re.compile(r'(\W+)')
p.split(s)
Tags: python, string, list, split | stackoverflow-qa |
# How do I split a string into a list?
## Question
If I have this string:
2+24*48/32
what is the most efficient approach for creating this list:
['2', '+', '24', '*', '48', '/', '32']
## Answer
You can use split from the re module.
re.split(pattern, string, maxsplit=0, flags=0)
Split string by the oc... | stackoverflow-qa |
# How do I split a string into a list?
## Question
If I have this string:
2+24*48/32
what is the most efficient approach for creating this list:
['2', '+', '24', '*', '48', '/', '32']
## Answer
This looks like a parsing problem, and thus I am compelled to present a solution based on parsing techniques.
Whi... | stackoverflow-qa |
# How do I split a string into a list?
## Question
If I have this string:
2+24*48/32
what is the most efficient approach for creating this list:
['2', '+', '24', '*', '48', '/', '32']
## Answer
>>> import re
>>> re.findall(r'\d+|\D+', '2+24*48/32=10')
['2', '+', '24', '*', '48', '/', '32', '=', '10']
Mat... | stackoverflow-qa |
# How do I split a string into a list?
## Question
If I have this string:
2+24*48/32
what is the most efficient approach for creating this list:
['2', '+', '24', '*', '48', '/', '32']
## Answer
Another solution to this would be to avoid writing a calculator like that altogether. Writing an RPN parser is muc... | stackoverflow-qa |
# How do I split a string into a list?
## Question
If I have this string:
2+24*48/32
what is the most efficient approach for creating this list:
['2', '+', '24', '*', '48', '/', '32']
## Answer
This is a parsing problem, so neither regex not split() are the "good" solution. Use a parser generator instead.
... | stackoverflow-qa |
# How do I split a string into a list?
## Question
If I have this string:
2+24*48/32
what is the most efficient approach for creating this list:
['2', '+', '24', '*', '48', '/', '32']
## Answer
It just so happens that the tokens you want split are already Python tokens, so you can use the built-in tokenize ... | stackoverflow-qa |
# How do I split a string into a list?
## Question
If I have this string:
2+24*48/32
what is the most efficient approach for creating this list:
['2', '+', '24', '*', '48', '/', '32']
## Answer
>>> import re
>>> my_string = "2+24*48/32"
>>> my_list = re.findall(r"-?\d+|\S", my_string)
>>> print my_list
['2... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
import os
os.system("your command")
Note that this is dangerous, since the command isn't cleaned. I leave it up to you to goo... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
import os
cmd = 'ls -al'
os.system(cmd)
If you want to return the results of the command, you can use os.popen. However, this... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
Look at the subprocess module in the stdlib:
from subprocess import call
call(["ls", "-l"])
The advantage of subprocess vs s... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
I'd recommend using the subprocess module instead of os.system because it does shell escaping for you and is therefore much saf... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
https://docs.python.org/2/library/subprocess.html
...or for a very simple command:
import os
os.system('cat testfile')
Tags:... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
os.system has been superceeded by the subprocess module. Use subproccess instead.
Tags: python, shell, command, subprocess, ex... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
os.system is OK, but kind of dated. It's also not very secure. Instead, try subprocess. subprocess does not call sh directly... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
Here's a summary of the ways to call external programs and the advantages and disadvantages of each:
os.system("some_command ... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
I typically use:
import subprocess
p = subprocess.Popen('ls', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
f... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
There is another difference here which is not mentioned above.
subprocess.Popen executes the as a subprocess. In my case, I n... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
Some hints on detaching the child process from the calling one (starting the child process in background).
Suppose you want to... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
Check "pexpect" python library, too.
It allows for interactive controlling of external programs/commands, even ssh, ftp, telnet... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
subprocess.check_call is convenient if you don't want to test return values. It throws an exception on any error.
Tags: python... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
If what you need is the output from the command you are calling you can use subprocess.check_output since Python 2.7
>>> subpr... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
I always use fabric for this things like:
from fabric.operations import local
result = local('ls', capture=True)
print "Conten... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
os.system does not allow you to store results, so if you want to store results in some list or something subprocess.call works.... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
you can use Popen, then you can check procedure's status
from subprocess import Popen
proc = Popen(['ls', '-l'])
if proc.poll... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
Very simplest way to run any command and get result back:
from commands import getstatusoutput
try:
return getstatusoutpu... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
I quite like shell_command for its simplicity. It's built on top of the subprocess module.
Tags: python, shell, command, subp... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
This is how I run my commands. This code has everything you need pretty much
from subprocess import Popen, PIPE
cmd = "ls -l ~... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
Update:
subprocess.run is the recommended approach as of Python 3.5 if your code does not need to maintain compatibility with ... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
With Standard Library
Use subprocess module:
from subprocess import call
call(['ls', '-l'])
It is the recommended standard ... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
There are a lot of different ways to run external commands in python,
and all of them have their own plus sides and drawbacks.... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
without the output of result
import os
os.system("your command here")
with output of result
import commands
commands.getout... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
Just to add to the discussion, if you include using a Python console, you can call external commands from ipython. While in the... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
After some research, I have the following code which works very well for me. It basically prints both stdout and stderr in real... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
Use subprocess.call:
from subprocess import call
# using list
call(["echo", "Hello", "world"])
# single string argument va... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
I tend to use subprocess together with shlex (to handle escaping of quoted strings):
>>> import subprocess, shlex
>>> command ... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
Shameless plug, I wrote a library for this :P
https://github.com/houqp/shell.py
It's basically a wrapper for popen and shlex f... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
A simple way is to use the os module:
import os
os.system('ls')
Alternatively you can also use the subprocess module
import... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
There is also Plumbum
>>> from plumbum import local
>>> ls = local["ls"]
>>> ls
LocalCommand(<LocalPath /bin/ls>)
>>> ls()
u'b... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
import os
cmd = 'ls -al'
os.system(cmd)
os - This module provides a portable way of using operating system dependent funct... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
Using Popen function of subprocess python module is the simplest way of running linux commands. In that, Popen.communicate() fu... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
Here are my 2 cents: In my view this is best practice when dealing with external commands...
This is return values from execut... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
For python 3.5+ it is recommended that you use the run function from the subprocess module. This returns a CompletedProcess obj... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
I would recommend the following method 'run' and it will help us in getting STDOUT, STDERR and exit status as dictionary; The c... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
import subprocess
p = subprocess.Popen("df -h", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
p... | stackoverflow-qa |
# Calling an external command in Python
## Question
How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
## Answer
To fetch the network id from the openstack neutron:
#!/usr/bin/python
import os
netid= "nova net-list | awk '/ External / { pr... | stackoverflow-qa |
# How do I verify that a string only contains letters, numbers, underscores and dashes?
## Question
I know how to do this if I iterate through all of the characters in the string but I am looking for a more elegant method.
Thanks
## Answer
A regular expression will do the trick with very little code:
import re
...... | stackoverflow-qa |
# How do I verify that a string only contains letters, numbers, underscores and dashes?
## Question
I know how to do this if I iterate through all of the characters in the string but I am looking for a more elegant method.
Thanks
## Answer
pat = re.compile ('[^\w-]')
def onlyallowed(s):
return not pat.search (... | stackoverflow-qa |
# How do I verify that a string only contains letters, numbers, underscores and dashes?
## Question
I know how to do this if I iterate through all of the characters in the string but I am looking for a more elegant method.
Thanks
## Answer
There are a variety of ways of achieving this goal, some are clearer than oth... | stackoverflow-qa |
# How do I verify that a string only contains letters, numbers, underscores and dashes?
## Question
I know how to do this if I iterate through all of the characters in the string but I am looking for a more elegant method.
Thanks
## Answer
As an alternative to using regex you could do it in Sets:
from sets import S... | stackoverflow-qa |
# How do I verify that a string only contains letters, numbers, underscores and dashes?
## Question
I know how to do this if I iterate through all of the characters in the string but I am looking for a more elegant method.
Thanks
## Answer
If it were not for the dashes and underscores, the easiest solution would be
... | stackoverflow-qa |
# How do I verify that a string only contains letters, numbers, underscores and dashes?
## Question
I know how to do this if I iterate through all of the characters in the string but I am looking for a more elegant method.
Thanks
## Answer
[Edit] There's another solution not mentioned yet, and it seems to outperfor... | stackoverflow-qa |
# How do I verify that a string only contains letters, numbers, underscores and dashes?
## Question
I know how to do this if I iterate through all of the characters in the string but I am looking for a more elegant method.
Thanks
## Answer
Well you can ask the help of regex, the great in here :)
code:
import re
s... | stackoverflow-qa |
# Issue with Regular expressions in python
## Question
Ok, so i'm working on a regular expression to search out all the header information in a site.
I've compiled the regular expression:
regex = re.compile(r'''
<h[0-9]>\s?
(<a[ ]href="[A-Za-z0-9.]*">)?\s?
[A-Za-z0-9.,:'"=/?;\s]*\s?
[A-Za-z0-9.,:'"=/... | stackoverflow-qa |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.