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 ?
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]
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
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
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?
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!
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, 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
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...
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
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.
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.
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]
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
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?
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')
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 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?
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.
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?
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!
Is there any way to have Python operators line "==" and "" return ints instead of bools. I know that I could use the int function (int(1 == 1)) or add 0 ((1 == 1) + 0) but I was wondering if there was an easy way to do it. Like when you want division to return floats you could type from __future__ import division. Is there any way to do this with operators returning ints? Or could I make a class extending __future__._Feature that would do what I want?