python

BeanStalkd on Solaris doesnt return anything when called from the python library

i am using Solaris 10 OS(x86). i installed beanstalkd and it starts fine by using command "beanstalkd -d -l hostip -p 11300". i have Python 2.4.4 on my system i installed YAML and beanstalkc python libraries to connect beanstalkd with python my problem is when i try to write some code: import beanstalkc beanstalk = beanstalkc.Connectio...

Is Pylons enterprise-ready?

I am a developer who is looking for an Enterprise-ready web application framework for Python. My main concern is long-term support, extensive feature set and reliability. I have been experimenting with Pylons and after my horrendous experience with Ruby on Rails on Windows where I even had to compile my own Postgres driver, Pylons and P...

Unable to solve a Python error message

The code is from K. Pollari-Malmi's lecture notes for the course "Introduction to Programming": def main(): print "Ohjelma laskee asuntolainan kuukausierat." rivi = raw_input("Anna lainasumma: ") lainasumma = float(rivi) rivi = raw_input("Anna laina-aika vuosina: ") laina_aika = int(rivi) if laina_aika < 1: ...

What's the different between "2*2" and "2**2" in Python?

What is the difference between the following codes? code1 var=2**2*3 code2 var2=2*2*3 I see no difference. This raises the following question. Why is the code1 used if we can use code2? ...

Unable to understand a line of Python code exactly

Alex's answer has the following line when translated to English print "%2d. %8.2f %8.2f %8.2f" % ( i, payment, interest, monthPayment) I am unsure about the line "%2d. %8.2f %8.2f %8.2f" % #Why do we need the last % here? It seems to mean the following apply %2d. to i apply %8.2f to payment apply %8.2f to ...

How to create Fibonacci Sequence in Java

I really suck at math. I mean, I REALLY suck at math. I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this: a = 0 b = 1 while b < 10: print b a, b = b, b+a The problem is that I can't really make this work in any other language. I'd...

Is there any good reason to convert an app written in python to c#?

I have written several Python tools for my company. Is there any good reason to convert them from Python to C# now that their usefulness has been proven? Would I be better off just leaving them in Python? ...

How do you create an incremental ID in a Python Class

I would like to create a unique ID for each object I created - here's the class: class resource_cl : def __init__(self, Name, Position, Type, Active): self.Name = Name self.Position = Position self.Type = Type self.Active = Active I would like to have a self.ID that auto increments everytime I cre...

Can I use Win32 COM to replace text inside a word document?

I have to perform a large number of replacements in some documents, and the thing is, I would like to be able to automate that task. Some of the documents contain common strings, and this would be pretty useful if it could be automated. From what I read so far, COM could be one way of doing this, but I don't know if text replacement is s...

Formatting output when writing a list to textfile

Hello, i have a list of lists that looks like this: dupe = [['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'apa.txt'], ['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'knark.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696', 'ron\\a', 'apa2.txt'], ['b5cc17d3a35877ca8b76f0b2e07497039c250696', 'ron\\a', 'jude.txt']] I w...

HTTPS log in with urllib2

I currently have a little script that downloads a webpage and extracta somw data I'm interested in. Nothing fancy. Currently I'm downloading the page like so: import commands command = 'wget --output-document=- --quiet --http-user=USER --http-password=PASSWORD https://www.example.ca/page.aspx' status, text = commands.getstatusoutput(co...

Install pyCurl in ActivePython-2.6?

I have worked with pyCurl in the past and have it working with my system default python install. However, I have a project that requires python to be more portable and I am using ActivePython-2.6. I have had no problems installing any other modules so far, but am getting errors installing pyCurl. The error: Searching for pycurl Readi...

Would one have to know the machine architecture to write code?

Let's say I'm programming in Java or Python or C++ for a simple problem, could be to build an TCP/UDP echo server or computation of factorial. Do I've to bother about the architecture details, i.e., if it is 32 or 64-bit? IMHO, unless I'm programming something to do with fairly low-level stuff then I don't have to bother if its 32 or 64...

python classes that refer to each other

I have two classes that refer to each other, but obviously the compiler complains. Is there any way around this? EDIT Actually my code is slightly different than what Hank Gay uses. So python can definitely deal with some kinds of circular references, but it tosses an error in the following situation. Below is what I've got and I ge...

wxpython: How can I redraw something when a window is retored?

In my wx.Frame based wxpython application, I draw some lines on a panel when some events occur by creating wx.ClientDC instances when needed. The only problem is, if the window is minimized and then restored, the lines disappear! Is there some kind of method that I should override or event to bind to that will allow me to call the drawin...

python observer pattern

I'm new to python but I've run into a hitch when trying to implement a variation of the observer pattern. class X(models.Model): a = models.ForeignKey(Voter) b = models.CharField(max_length=200) # Register Y.register(X) This doesn't seem to work because it says X is not defined. A couple of things are possible: A) ...

Python - Subprocess - How to call a Piped command in Windows?

How do I run this command with subprocess? I tried: proc = subprocess.Popen( '''ECHO bosco|"C:\Program Files\GNU\GnuPG\gpg.exe" --batch --passphrase-fd 0 --output "c:\docume~1\usi\locals~1\temp\tmptlbxka.txt" --decrypt "test.txt.gpg"''', stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ) stdout_va...

Unable to put a variable in Python's print

My code: year=[51-52,53,55,56,58,59,60,61] photo=[{70,72,73},{64,65,68},{79,80,81,82},{74,77,78},{60,61,62},{84,85,87},{57,58,59},{53,54,55,56}] for i in range(7): print "<img src=\"http://files.getdropbox.com/u/100000/Akuja/",year,"/P10104",photo,".JPG\"&gt;" I run it and I get File "/tmp/aku.py", line 2 photo=[{70,72,73},{...

Importing Python modules from different working directory

I have a Python script that uses built-in modules but also imports a number of custom modules that exist in the same directory as the main script itself. For example, I would call python agent.py and agent.py has a number of imports, including: import checks where checks is in a file in the same directory as agent.py agent/agent....

An integer is required? open()

I have a very simple python script that should scan a text file, which contains lines formatted as id='value' and put them into a dict. the python module is called chval.py and the input file is in.txt. here's the code: import os,sys from os import * from sys import * vals = {} f = open(sys.argv[1], 'r') for line in val_f: t = li...