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'm trying to get started with unit testing in Python and I was wondering if someone could inform me of the advantages and disadvantages of doctest and unittest. What conditions would you use each for?
I'm using Python to process CSV files filled with data that I want to run calculations on, and then graph. I'm looking for a library to use that I can send processed CSV information to, or a dict of some sort, and then choose different graphing styles with.
Does anyone have any recommendations?
Hi Guys,
I am creating a GUI frontend for the Eve Online API in Python.
I have successfully pulled the XML data from their server.
I am trying to grab the value from a node called "name"
from xml.dom.minidom import parse
dom = parse("C:\\eve.xml")
name = dom.getElementsByTagName('name')
print name
This seems to find the node ok but the output is below:
[<DOM Element: name at 0x11e6d28>]
How could I get it to print the value of the node?
Cheers
I'm trying to parse the output from a tool into a data structure but I'm having some difficulty getting things right. The file looks like this:
Fruits
Apple
Auxiliary
Core
Extras
Banana
Something
Coconut
Vegetables
Eggplant
Rutabaga
You can see that top-level items are indented by one space, and items beneath that are indented by two spaces for each level. The items are also in alphabetical order.
How do I turn the file into a Python list that's something like ["Fruits", "Fruits/Apple", "Fruits/Banana", ..., "Vegetables", "Vegetables/Eggplant", "Vegetables/Rutabaga"]?
Hi,
I want to convert RGB values to HSV using python. I got some code samples, which gave the result with the S and V values greater than 100. (example : http://code.activestate.com/recipes/576554-covert-color-space-from-hsv-to-rgb-and-rgb-to-hsv/ ) . anybody got a better code which convert RGB to HSV and vice versa
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...
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 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 wonder if there are any best practices/patterns for deploying python apps on Google app engine specifically Django. The best practice should be combination of existing best practices viz. Fabric, Paver, Buildout etc. Also please share best practice patterns for developing (I could not get virtualenv running with Django and Django App engine helper)
Does anyone know how to do convert from a string to a boolean in Python? I found this link. But it doesn't look like a proper way to do it. I.e. using a built in functionality, etc.
EDIT: The reason I asked this is because I learned int("string"), from here. I tried bool ("string") but always got True.
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
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.
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 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 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 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.
Hello.
Are there any modules for python, that can be used as tftp server? I tried Tftpy, but when I try to upload something, it says:
ERROR:tftpy:Write requests not implemented at this time.
In fact, it's the only function that I need.
Mechanize (Python) is failing with 401 for me to open http digest URLs. I googled and tried debugging but no success.
My code looks like this.
import mechanize
project = "test"
baseurl = "http://trac.somewhere.net"
loginurl = "%s/%s/login" % (baseurl, project)
b = mechanize.Browser()
b.add_password(baseurl, "user", "secret", "some Realm")
b.open(loginurl)
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'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'
In python the function random() generates a random float uniformly in the semi-open range [0.0, 1.0). In principle can it ever generate 0.0 (i.e. zero) and 1.0 (i.e. unity)? What is the scenario in practicality?