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.
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 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.
Ok, so I've read both PEP 8 and PEP 257, and I've written lots of docstrings for functions and classes, but I'm a little unsure about what should go in a module docstring. I figured, at a minimum, it should document the functions and classes that the module exports, but I've also seen a few modules that list author names, copyright information, etc. Does anyone have an example of how a good python docstring should be structured?
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]
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?
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')
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
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
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.
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?
how is it possible to run import win32api successfully on a 64bit maya version 2008
following error occurs
Error: No module named win32api
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named win32api #
I need to get mouse cursor position in python so that i can place window exactly in that position. Is there any other way to get it
Brgds,
kNish
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?
Somehow, this works fine in the Maya/Python script editor, but fails when it's inside of my module code. Anyone have any ideas?
class ControlShape(object):
def __init__(self, *args, **kwargs):
print 'Inside ControlShape...'
class Cross(ControlShape):
def __init__(self, *args, **kwargs):
print 'Entering Cross...'
super(Cross, self).__init__(*args, **kwargs)
print 'Leaving Cross...'
x = Cross()
This gives me a TypeError: super(type, obj): obj must be an instance or subtype of type.
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 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?
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.
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!
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 wrote this code in VB to label columns in a table but now im writting a python script to automate the process and i can't make it work. Any thoughts??
Static v1 as variant
Static v2 as variant
Dim Output as double
Dim Start as double
Start = 1
If v2 = [XMIN] Then
Output = v1
Else
Output = v1 + 1
End If
v1 = Output
v2 = [XMIN]
Hi
I new to python and I read from someone else of the example code below:
class A:
def current(self):
data = Data(a=a,b=b,c=c)
return data
class B(A):
#something here
#print data a b c
How do I print out the data a, b, and c?
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'm looking for a way to programatically control a browser on a Mac (i.e. not IE) using Python.
The actions I need include following links, checking if elements exist in a page, and submitting forms.
Which solution would you recommend?
Thanks!