This is running on Windows 7 (64 bit), Python 2.6 with Win32 Extensions for Python.
I have a simple script that just print "hello world". I can launch it with python hello.py. In this case I can redirect the output to a file. But if I run it by just typing hello.py on the command line and redirect the output, I get an exception.
C:> py...
I am trying to create python bindings to a vala library using the following IBM tutorial as a reference.
My initial directory has the following two files:
test.vala
using GLib;
namespace Test {
public class Test : Object {
public int sum(int x, int y) {
return x + y;
}
}
}
test.override
%%
header...
Hi
I am new to Python.
Say I have a list:
list = ['A','B','C','D']
The key for each item respectively here is 0,1,2,3 - right?
Now I am going to loop through it with a for loop...
for item in list:
print item
That's great, I can print out my list.
How do I get the key here? For example being able to do:
print key
print ite...
I have a dataset of events (tweets to be specific) that I am trying to bin / discretize. The following code seems to work fine so far (assuming 100 bins):
HOUR = timedelta(hours=1)
start = datetime.datetime(2009,01,01)
z = [dt + x*HOUR for x in xrange(1, 100)]
But then, I came across this fateful line at python docs 'This makes possib...
Given this example, I get the error that follows:
print u'\2033'.translate({2033:u'd'})
C:\Python26\lib\encodings\cp437.pyc in encode(self, input, errors)
10
11 def encode(self,input,errors='strict'):
---> 12 return codecs.charmap_encode(input,errors,encoding_map)
13
14 def decode(self,input,errors='...
Hi SO,
I can't seem to create the correct regular expression to extract the correct tokens from my string. Padding the beginning of the string with a space generates the correct output, but seems less than optimal:
>>> import re
>>> s = '-edge_0triggered a-b | -level_Sensitive c-d | a-b-c'
>>> re.findall(r'\W(-[\w_]+)',' '+s)
['-edge_0...
im trying to build android from source on ubuntu 10.04. when i enter the repo command:
repo init -u git://android.git.kernel.org/platform/manifest.git -b eclair
it get this error back
exec: 23: python: not found
any ideas.
...
How do I do a command that will set the default value on a Tkinter spinbox widget?
For some reason they didn't give it the attribute .set()
...
I have a project that used to be under SVN, but now I'm moving it to Mercurial, so I want to clear out all the .svn files.
It's a little too big to do it by hand, so I decided to write a python script to do it. But it isn't working.
def cleandir(dir_path):
print "Cleaning %s\n" % dir_path
toDelete = []
files = os.listdir(di...
I have a list in python ('A','B','C','D','E'), how do I get which item is under a particular index number?
Example:
Say it was given 0, it would return A.
Given 2, it would return C.
Given 4, it would return E.
...
I have model, Match, with two foreign keys:
class Match(model.Model):
winner = models.ForeignKey(Player)
loser = models.ForeignKey(Player)
When I loop over Match I find that each model instance uses a unique object for the foreign key. This ends up biting me because it introduces inconsistency, here is an example:
>>> def print...
I'm trying to delete old SVN files from directory tree. shutil.rmtree and os.unlink raise WindowsErrors, because the script doesn't have permissions to delete them. How can I get around that?
Here is the script:
# Delete all files of a certain type from a direcotry
import os
import shutil
dir = "c:\\"
verbosity = 0;
def printCleanM...
main:.
├─a
│ ├─__init__.py
│ └─aa.py
├─b
│ ├─__init__.py
│ └─bb.py
└─cc.py
if i am in aa.py , how to import cc.py ?
this is my code ,but it is error :
from main import cc
what should i do .
thanks
updated
in normal python file (not on gae),i can use this code :
import os,sys
dirname=os.path.dirname
path=os.path....
I'm trying to get the first href attribute in a page using Selenium RC (in Python):
sel.get_text("xpath=//@href")
this returns an empty string.
However, an identical xpath on the same page inside Firefox (using the "View XPath" extension) yields the correct value.
I've tried fiddling with it, but the same happens for other attribute...
Hi all,
I have a small question regarding the Django database query system. I have seen that most of the code we find over internet, forums or even in a tutorials, it uses queries like :
user = User.objects.all() or User.objects.filter(username = username)
but this will fetch all the columns of the table even if we do not need all th...
I am using the h5py python package to read files in HDF5 format. (e.g. somefile.h5)
I would like to write the contents of a dataset to a text file.
For example, I would like to create a text file with the following contents:
1,20,31,75,142,324,78,12,3,90,8,21,1
I am able to access the dataset in python using this code:
import h5py
f ...
I was wondering how to make a python script portable to both linux and windows?
One problem I see is shebang. How to write the shebang so that the script can be run on both windows and linux?
Are there other problems besides shebang that I should know?
Is the solution same for perl script?
Thanks and regards!
...
i have a file of this format:
3.334 1
2.345 1
1.453 1
3.343 1
and so on
but in middle at times in file there are few number which are not in float format and i receive type msg when i run them performation some operation..
I want to give a condition that:
if(not in float format):
continue
else:
perform operation
please tell me...
I'm trying to figure out how to map against a simple read-only property and have that property fire when I save to the database.
A contrived example should make this more clear. First, a simple table:
meta = MetaData()
foo_table = Table('foo', meta,
Column('id', String(3), primary_key=True),
Column('description', String(64), ...
I am filling a python dict with around 10,000,000 items. My understanding of dict (or hashtables) is that when too much elements get in them, the need to resize, an operation that cost quite some time.
Is there a way to say to a python dict that you will be storing at least n items in it, so that it can allocate memory from the start? O...