How can i mesure and compare the running times of my algorithms written in python .Also point me to a nice algorithms site/forum like stackoverflow if you can.
What tools are good to use for code analysis in python?
I have a large source repository split across multiple projects, and I would like to be able to run tools across the directories to see details like Cyclomatic Complexity, and perhaps be able to spot errors using static analysis.
Ideally, I would like to be able to produce a report about the health of the source code, so we can spot problem areas that need to be addressed.
Let say i want to read the integers a, b and c from stdin (in one line, do not need to press return after each number). In c++, i would just do:
cin a b c;
How to do this in Python ?
I have a Python script that pulls in data from many sources (databases, files, etc.). Supposedly, all the strings are unicode, but what I end up getting is any variation on the following theme (as returned by repr()):
u'D\\xc3\\xa9cor'
u'D\xc3\xa9cor'
'D\\xc3\\xa9cor'
'D\xc3\xa9cor'
Is there a reliable way to take any four of the above strings and return the proper unicode string?
u'D\xe9cor' # --> Décor
The only way I can think of right now uses eval(), replace(), and a deep, burning shame that will never wash away.
can you convert this perl code to python code :
$list = $ARGV[0];
open (PASSFILE, "$list") || die "[-] Can't open the List of password file !";
@strings = ;
close PASSFILE;
Thanks
Hey im new to python. How do you get a portion of a list by the relative value of its sorting key.
example...
list = [11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10]
list.sort()
newList = list.split("all numbers that are over 13")
assert newList == [14,15,16]
Hi, I have a CSV file and I want to bulk-import this file into my sqlite3 database using Python. the command is ".import .....". but it seems that it cannot work like this. Can anyone give me an example of how to do it in sqlite3? I am using windows just in case.
Thanks
I'm trying to rewrite the equivalent of the python replace() function without using regexp. Using this code, i've managed to get it to work with single chars, but not with more than one character:
def Replacer(self, find_char, replace_char):
s = []
for char in self.base_string:
if char == find_char:
char = replace_char
#print char
s.append(char)
s = ''.join(s)
my_string.Replacer('a','E')
Anybody have any pointers how to make this work with more than one character? example:
my_string.Replacer('kl', 'lll')
If possible I would like to use the following structure for a command however I can't seem to figure out how to achieve this in Python:
./somescript.py arg <optional argument> -- "some long argument"
Would it be possible to achieve this in a feasible manner without too much dirty code? Or should I just reconsider the syntax (which is primarily preference).
Thanks!
If I point Firefox at http://bitbucket.org/tortoisehg/stable/wiki/Home/ReleaseNotes, I get a page of HTML. But if I try this in Python:
import urllib
site = 'http://bitbucket.org/tortoisehg/stable/wiki/Home/ReleaseNotes'
req = urllib.urlopen(site)
text = req.read()
I get the following:
500 Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
What am I doing wrong?
Here's the code, I don't quite understand, how does it work. Could anyone tell, is that an expected behavior?
$ipython
In [1]: 1 in [1] == True
Out[1]: False
In [2]: (1 in [1]) == True
Out[2]: True
In [3]: 1 in ([1] == True)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/dmedvinsky/projects/condo/condo/<ipython console> in <module>()
TypeError: argument of type 'bool' is not iterable
In [4]: from sys import version_info
In [5]: version_info
Out[5]: (2, 6, 4, 'final', 0)
Hi,
I'm building a download manager in python for fun, and sometimes the connection to the server is still on but the server doesn't send me data, so read method (of HTTPResponse) block me forever. This happens, for example, when I download from a server, which located outside of my country, that limit the bandwidth to other countries.
How can I set a timeout for the read method (2 minutes for example)?
Thanks, Nir.
What's the idiomatic way to do maximumBy (higher order function taking a comparison function for the test), on a list of lists, where the comparison we want to make is the sum of the list, in Python?
Here's a Haskell implementation and example output:
> maximumBy (compare `on` sum) [[1,2,3],[4,5,6],[1,3,5]]
> [4,5,6]
I am trying to retrieve a 500mb file using Python, and I have a script which uses urllib.urlretrieve(). There seems to some network problem between me and the download site, as this call consistently hangs and fails to complete. However, using wget to retrieve the file tends to work without problems. What is the difference between urlretrieve() and wget that could cause this difference?
Hi All
I would like to handle time series in python.
I have been suggested to use scikit.timeseries but I need to handle up to microseconds and this last, as far as I know, handles up to milliseconds.
Do you know any other library able to do that? At some point I need to merge 2 time series sampled at different time, and I would like to avoid rewriting such kind of features or any new classes from scratch whenever it is possible.
I thank you all
AFG
I want to write a custom DVD player using python that plays for 30 seconds, then pauses and asks a question. Once the question is anwered, it tells the user if they are right or wrong and gives them a Resume button to resume DVD playback. How do I do this. I have never written a DVD player before, but I am open to learning!
I have a lot of Perl scripts that looks something like the following. What it does is that it will automatically open any file given as a command line argument and in this case print the content of that file. If no file is given it will instead read from standard input.
while ( <> ) {
print $_;
}
Is there a way to do something similar in Python without having to explicitly open each file?
What is the best way to implement the singleton pattern in Python? It seems impossible to declare the constructor private or protected as is normally done with the Singleton pattern...
I need to count the number of files in a directory using Python.
I guess the easiest way is len(glob.glob('*')), but I also count the directory as file.
Is there any way to count only the files in a directory?
Hello,
I have a Python script and I want to call it several functions down the script. Example code below:
class Name():
def __init__(self):
self.name = 'John'
self.address = 'Place'
self.age = '100'
def printName(self):
print self.name
def printAddress(self):
print self.address
def printAge(self):
print self.age
if __name__ == '__main__':
Person = Name()
Person.printName()
Person.printAddress()
Person.printage()
I execute this code by entering ./name.py. How could I exectute this code from the function printAddress() down the the end of the script?
Thanks
Hello, I am getting a compile error, saying that the copy constructor of the scoped_ptr is private with the following code snippet:
class a {};
struct s
{
boost::scoped_ptr<a> p;
};
BOOST_PYTHON_MODULE( module )
{
class_<s>( "s" );
}
This example works with a shared_ptr though. It would be nice, if anyone knows the answer. Thanks
Hello,
I am trying to understand the advantages of the module Multiprocessing over Threading. I know that Multiprocessing get's around the Global Interpreter Lock, but what other advantages are there, and can threading not do the same thing?
I am new to distutils.. I am trying to include few data files along with the package.. here is my code..
from distutils.core import setup
setup(name='Scrapper',
version='1.0',
description='Scrapper',
packages=['app', 'db', 'model', 'util'],
data_files=[('app', ['app/scrapper.db'])]
)
The zip file created after executing python setup.py sdist does not include the scrapper.db file. I have scrapper.db file in the app directory..
thanks for the help.