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 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 list in python which has following entries
name-1
name-2
name-3
name-4
name-1
name-2
name-3
name-4
name-1
name-2
name-3
name-4
I would like remove name-1 from list except its first appearance -- resultant list should look like
name-1
name-2
name-3
name-4
name-2
name-3
name-4
name-2
name-3
name-4
How to achieve this ?
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.
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.
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
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.
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 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.
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?
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'
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?
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 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.
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
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.
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.
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!
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?
I'm learning perl and everytime I search for perl stuff in the internet I get some random page with people saying that perl should die because code written in it looks like a lesson in steganography. Then they say that python is clean and stuff like that. Now, I know that those comparisons are always stupid and made by fellows that feel that languages are a extension of their boring personality so, let me ask instead: can you give me the implementation of a widely known algorithm to deal with a data structure like red-black trees in both languages so I can compare?
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 am writing a python script that needs to make a log entry whenever it's invoked. The log created by the script must not be changeable by the user (except root) who invoked the script. I tried the syslog module and while this does exactly what I want in terms of file permissions, I need to be able to put the resulting log file in an arbitrary location. How would I go about doing this?
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
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.