python

add rights to a folder using python

I want to give anyone full access to a specific folder (+sub-folders +files in it). I tried that code: f = "c:\test" #... which is the folder #vars sidWorld = win32security.CreateWellKnownSid(win32security.WinWorldSid, None) worldRights = win32file.FILE_ALL_ACCESS #get DACL fileSecDesc = win32security.GetNamedSecurityInfo( \ f, wi...

Python: generate random integers between 0 and 9

How can I generate random integers numbers between 0<9 (included extremes) in python ? i.e. 0 1 2 3 4 5 6 7 8 9 thanks ...

Python urllib urlencode problem with æøå

Hey .. How can I urlencode a string with special chars æøå? ex. urllib.urlencode('http://www.test.com/q=testæøå') I get this error :(.. not a valid non-string sequence or mapping object ...

Exception when running a Python method from another class.

Here is my code. import urllib2 import urllib import json from BeautifulSoup import BeautifulSoup class parser: """ This class uses the Beautiful Soup library to scrape the information from the HTML source code from Google Translate. It also offers a way to consume the AJAX result of the translation, however encodi...

Why urllib2 doesn't work for me ?

I have installed 3 different python script on my ubuntu 10.04 32 bit machine with python 2.6.5. All of these use the urllib2 and I always get this error: urllib2.URLError: <urlopen error [Errno 110] Connection timed out> Why ? Examples: >>> import urllib2 >>> response = urllib2.urlopen("http://www.google.com") Traceback (most recen...

Class has method that shows in intellisense, but gives an error when running it.

I'm tring to set the default encoding of my console to UTF-8 so it can display cyrillic letters and accented letters. Here is my code: from Parser import parser import sys print sys.getdefaultencoding() sys.setdefaultencoding('utf-8') Output: ascii Traceback (most recent call last): File "C:\Users\Sergio.Tapia\Documents\NetBeans...

How can I make contents of a txt file be used as subject for mail in linux?

Hi, I have a crontab file which executes a shell script as shown below 27 11 * * * /usr/python/bi_python/launcher/launch_script_leds.sh The shell script does a number of things: 1)executes python script launcher.py which runs tests and outputs to log files 2)sends mail notification when tests have completed with test output as body ...

Remove differences between two folders

Hi, can anyone please suggest a method (ruby, python or dos preferable) to remove only the different files and sub-folders between two given folders? I need it to recurse through sub-directories and delete everything that is different. I don't wanna have to install anything, so a script would be great. Thanks in advance ...

Python generator, non-swallowing exception in 'coroutine'

I recently came across some surprising behaviour in Python generators: class YieldOne: def __iter__(self): try: yield 1 except: print '*Excepted Successfully*' # raise for i in YieldOne(): raise Exception('test exception') Which gives the output: *Excepted Successfully* Traceback (most recent call last)...

Python: Replace with regex

Hello, I need to replace part of a string. I was looking through the Python documentation and found re.sub. import re s = '<textarea id="Foo"></textarea>' output = re.sub(r'<textarea.*>(.*)</textarea>', 'Bar', s) print output >>>'Bar' I was expecting this to print '<textarea id="Foo">Bar</textarea>' and not 'bar'. Could anybody te...

SWIG cross platform

My application is using SWIG to communicate between c++ and python on windows. suppose if my interface is "example.h" swig is generating example.py, example_wrap.cxx /* File : example.i */ %module example %{ #include "example.h" %} %include "std_string.i" %include "std_wstring.i" %include "example.h" I am porting my application ...

Merging .xlsx file with Python

Two-headed question here guys, First, I've been trying to do some searching for a way to read .xlsx files in python. Does xlrd read .xlsx files now? If not, what's the recommended way to read/write to such a file? Second, I have two files with similar information. One primary field with scoping subfields (like coordinates(the primary ...

what would be a quick way to read a property file in python?

I have a file with the format VarName=Value . . I want to read it into a hash such that H("VarName") will return the value. What would be a quick way? (read a set of strings, split all of them where the equality sign is, and then put it into a hash? I am working with python. ...

Specific Quote Issue

Hey everyone, Here is my problem. I have a model Project, that has a quote field in it. When a new instance of project is created I need to append the last 2 digits of the year plus a hyphen onto the start of the "quote" field. Ex. 2010 = "10-". Im just not quite sure how to start it? As of right now I have hard coded in "10-" in a...

HTML code processing

Hello, I want to process some HTML code and remove the tags as in the example: "<p><b>This</b> is a very interesting paragraph.</p>" results in "This is a very interesting paragraph." I'm using Python as technology; do you know any framework I may use to remove the HTML tags? Thanks! ...

svg image - zoom and borders.

I have the following small svg file hosted at: http://dl.dropbox.com/u/7393/hmap.svg and I am trying to make it look like this: http://dl.dropbox.com/u/7393/final.png The docs where I got this from mentions that this change can be easily obtained by changing a couple of tags on the svg file. However I have tried changing everything and ...

[Python 3] Base64 decode until there is no Base64

Hello from Germany So my problem is something very simple, i think. I need to Decode Base64 until there is no Base64, i check with an RegEx if there is some Base64 but i got no Idea how to decode until there is no Base64. In this short Code i can Decode the Base64 until there is no Base64 because my Text is defined. (Until the Base64 D...

Why does this SQLAlchemy example commit changes to the DB?

This example illustrates a mystery I encountered in an application I am building. The application needs to support an option allowing the user to exercise the code without actually committing changes to the DB. However, when I added this option, I discovered that changes were persisted to the DB even when I did not call the commit() meth...

Why my code doesn't work?

Why doesn't this work? for i in [a, b, c]: i.SetBitmap(wx.Bitmap(VarFiles[str(i)])) I get: Traceback (most recent call last): File "<string>", line 11, in ? File "codecc.py", line 724, in ? app = MyApp(0) # stdio to console; nothing = stdio to its own window File "C:\Program Files (x86)\WorldViz\Vizard30\bin\lib\site-...

Python Facebook login

How can I make a Python script which checks if I have logged in the Facebook? If I haven't, it should log me in. ...