Most of us know that the command random.randint(1,n) in Python (2.X.X) would generate a number in random (pseudo-random) between 1 and n. I am interested in knowing what is the upper limit for n ?
I know that classes can implement various special methods, such as __iter__, __setitem__, __len__, __setattr__, and many others. But when should I use them? Can anyone describe typical scenarios when I would want to implement them and they would simplify programming in Python?
Thanks, Boda Cydo.
I do Java programming and recently started learning Python via the official documentation.
I see that we can dynamically add data attributes to an instance object unlike in Java:
class House:
pass
my_house = House()
my_house.number = 40
my_house.rooms = 8
my_house.garden = 1
My question is, in what situations is this feature used? What are the advantages and disadvantages compared to the way it is done in Java?
I have an xml file in the following format:
<food>
<desert>
cake
<desert>
</food>
<history>
currently in my belly
</history>
I want to create two list, food and text populated with cake and history in string format. Is there an easy way to do it in python?
I'm trying to put comments in when compiling a regex but when using the re.VERBOSE flag I get no matchresult anymore.
(using Python 3.3.0)
Before:
regex = re.compile(r"Duke wann", re.IGNORECASE)
print(regex.search("He is called: Duke WAnn.").group())
Output: Duke WAnn
After:
regex = re.compile(r'''
Duke # First name
Wann #Last Name
''', re.VERBOSE | re.IGNORECASE)
print(regex.search("He is called: Duke WAnn.").group())`
Output:
AttributeError: 'NoneType' object has no attribute 'group'
Does anyone know if Python's shelve module uses memory-mapped IO?
Maybe that question is a bit misleading. I realize that shelve uses an underlying dbm-style module to do its dirty work. What are the chances that the underlying module uses mmap?
I'm prototyping a datastore, and while I realize premature optimization is generally frowned upon, this could really help me understand the trade-offs involved in my design.
hi;
i need grab to firefox address bar. how to get address bar url for python ? (i need second part other browsers chrome and safari grabbing address bar but firefox is urgently).
Thanks.
In another question, the accepted answer suggested replacing a (very cheap) if statement in Python code with a try/except block to improve performance.
Coding style issues aside, and assuming that the exception is never triggered, how much difference does it make (performance-wise) to have an exception handler, versus not having one, versus having a compare-to-zero if-statement?
We are going to use Google Appengine platform for our next big web project.But we are not sure which flavour to use: Java or Python.
Could you please, advise on cons and pros of each approach? Which is the best way in order to build more scalable and efficient solution quicker.
Thanks in advance
Hello folks,
I am implementing caching for my Python application and I want to use memcached. Which module do you suggest me to use? There are so many that I don't know which one to choose.
Thanks, Boda Cydo.
I have a python app which is supposed to be very long-lived, but sometimes the process just disappears and I don't know why. Nothing gets logged when this happens, so I'm at a bit of a loss.
Is there some way in code I can hook in to an exit event, or some other way to get some of my code to run just before the process quits? I'd like to log the state of memory structures to better understand what's going on.
I am developing a python adapter to interact with a 3rd party website, without any json or xml api (http://www.class.noaa.gov/).
I have a problem when Travis CI run multiple python tests (of the The Travis CI Build Matrix) concurrently.
The project is on GitHub at ecolell/noaaclass and the .travis.yml file is:
language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
install:
- "make deploy"
script: "make test-coverage-travis-ci" #nosetests
after_success:
- "make test-coveralls"
Specifically, I have a problem when at least 2 python versions were running their unit tests at the same time, because they use the same account of a website.
Is there any option to specify to The Build Matrix the execution of each python version in a secuential way?
Or maybe, Is there a better way to do this?
I don't know python and I'm porting a library to C#, I've encountered the following lines of code that is used in some I/O operation but I'm not sure what it is, my guess is that it's a hexadecimal but I don't know why it's inside a string, neither what the backslashes do?
sep1 = '\x04H\xfe\x13' # record separator
sep2 = '\x00\xdd\x01\x0fT\x02\x00\x00\x01' # record separator
I am having some trouble getting appscript installed on OS/X 10.6.3 / Python 2.6.1. When I issue
sudo easy_install appscript
I get "unable to execute gcc-4.2: No such file or directory". Even when I do export CC=/Developer/usr/bin/gcc-4.2 (a valid gcc-4.2 executable), easy_install barks.
What could be the issue?
Disclaimer: OS/X newbie at the helm...
I am trying to add a few extra methods to a matrix type from the pysparse library. Apart from that I want the new class to behave exactly like the original, so I chose to implement the changes using inheritance. However, when I try
from pysparse import spmatrix
class ll_mat(spmatrix.ll_mat):
pass
this results in the following error
TypeError: Error when calling the metaclass bases
cannot create 'builtin_function_or_method' instances
What is this causing this error? Is there a way to use delegation so that my new class behaves exactly the same way as the original?
how can I get the list of cross product pairs from a list of arbitrarily long lists in python? e.g.
a = [1,2,3]
b = [4,5,6]
crossproduct(a,b) should yield [[1,4], [1, 5], [1,6], ...]
thanks.
I would like to pass some options to Python (version 2.6) every time, not just in interactive mode. Is there a file I can put such commands in?
EDIT: Specifically, I'm wanting to silence the Deprecation warnings.
Hi,
Does anybody know if there is a free python chess moves validation function available somewhere?
What I need. I have a diagram stored as a string, and move candidate. What I need is to see if move candidate is valid for the diagram.
Would be really interested to see examples, if possible.
Hi folks,
I'm having a problem with my python script.
It's printing massive amounts of data on the screen, and I would like to prevent all sorts of printing to screen.
Any ideas?
Help would be amazing and very much appreciated!
I'm not a Perl user, but from this question deduced that it's exceedingly easy to retrieve the standard output of a program executed through a Perl script using something akin to:
$version = `java -version`;
How would I go about getting the same end result in Python? Does the above line retrieve standard error (equivalent to C++ std::cerr) and standard log (std::clog) output as well? If not, how can I retrieve those output streams as well?
Thanks,
Geoff
It seems like there should be a simpler way than:
import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
Is there?
hi,
in python, how can a custom format-specification be added, to a class ? for example, if i write a matrix class, i would like to
define a '%M' (or some such) which would then dump the entire contents of the matrix...
thank you
kind regards
anupam
Hello.
I need a recommendation for a pythonic library that can marshall python objects to XML(let it be a file).
I need to be able read that XML later on with Java (JAXB) and unmarshall it.
I know JAXB has some issues that makes it not play nice with .NET XML libraries so a recommendation on something that actually works would be great.
Hi, I'm new here and on python too, and i need a code to login an HTTPS webpage
the page is: ritaj.birzeit.edu
and how can i know if its correct username or password , can you help in this :)