python

Matlab-like structure 'Cell Array' in Numpy?

i try to use create Cell Array in Numpy, Anyone have an Information ? ...

How to enable cookie support with pyWebKit?

The documentation for pyWebKitGTK is pretty scarce. I've looked through their python .def files but they don't seem to contain the words cookie, session, (lib)soup or (lib)curl.. so maybe it isn't possible, huh. I've also looked through the WebKitGTK docs (for the C-based library) and aside from a brief mention of libsoup there doesn't a...

Testing complex datatypes?

What's are some ways of testing complex data types such as video, images, music, etc. I'm using TDD and wonder are there alternatives to "gold file" testing for rendering algorithms. I understand that there's ways to test other parts of the program that don't render and using those results you can infer. However, I'm particularly interes...

Python: Read password from stdin

Scenario: An interactive CLI Python program, that is in need for a password. That means also, there's no GUI solution possible. In bash I could get a password read in without re-prompting it on screen via read -s Is there something similar for Python? I.e., password = raw_input('Password: ', dont_print_statement_back_to_screen) Al...

How to convert text into URL syntax on Python?

I want to convert python str to URL syntax. For example >>> u'한글'.encode('utf-8') '\xed\x95\x9c\xea\xb8\x80' to '%ed%95%9c%ea%b8%80' Thanks in advance. ...

How to integrate Disqus to Facebook Connect-enabled site (python Tornado app)

I succesfully use Facebook auth for my Tornado-based site using FacebookMixin. I also have Facebook Connect auth enabled for my Disqus, which placed in page using javascript widget. When user already logged in using FB to my site, they still have to log to FB again when they want to comment using Disqus. How Discus FB Connect suppose to...

How to create an ontology in python?

Are there libraries or certain "techniques" that you can use to create an ontology of elements? Or "design patterns"? I am talking about just a "graph" of things. Suppose I have a bunch of words. Certain words are "under" other words or "related" to other words. I need a good way to group them and know their relationship. ...

force unpacking of certain egg directories

I have an egg distribution of a PyQt application which i build myself, and it contains sphinx generated documentation. When i call the help file from the application it opens the sphinx index.html in a QtWebKit.QWebView window. Apparently, only the index.html file is extracted from the egg into the OS's egg-directory (e.g. [..]\Applicati...

how to get Company contact page url

Hi i have csv file which contains company url list like this www.google.com,www.ibm.com..... Here i want to get contactus or aboutus page url (example http://www.google.com/contact) for each url which is present in csv file i have one idea checking the links with the following patterns (contact us, about us, about, locations). If you ...

Adding Lists Elements to 'Mega List'

Let's say I have a list somewhere called majorPowers which contain these two lists: axis=["germany","italy","japan"] allies=["russia","uk","us"] I'd like to insert each of the elements of these lists, into a new mega-list. I'm currently doing this: >>> temp = [] >>> temp = [ww2.append(t) for t in majorPowers] >>>ww2 [['germany','ital...

How to find the position of an element in a list , in Python?

for s in stocks_list: print s how do I know what "position" s is in? So that I can do stocks_list[4] in the future? ...

encoding a string to ascii

I have a long string that I want to encode to ascii. I'm doing: s = s.encode('ascii', 'replace') but I get: 'ascii' codec can't decode byte 0xc3 in position 2646: ordinal not in range(128) (I've also tried 'ignore' but it doesn't help.) What am I doing wrong?? ...

Python Tesseract OCR question

I have this image: I want to read it to a string using python, which I didn't think would be that hard. I came upon tesseract, and then a wrapper for python scripts using tesseract. So I started reading images, and it's done great until I tried to read this one. Am i going to have to train it to read that specific font? Any ideas on ...

How do I do a "for each" , starting at a certain index of a list (Python)?

Suppose I have this list: thelist = ['apple','orange','banana','grapes'] for fruit in thelist: This would go through all the fruits. However, what if I wanted to start at orange? Instead of starting at apple? Sure, I could do "if ...continue", but there must be a better way? ...

Why is it when I print something, there is always a unicode next to it? (Python)

[u'Iphones', u'dont', u'receieve', u'messages'] Is there a way to print it without the "u" in front of it? ...

Scanning Keypress in Python

I have paused a script for lets say 3500 seconds by using time module for ex time.sleep(3500). Now, my aim is to scan for keypresses while the script is on sleep, i mean its on this line. Its like I want to restart the script if a "keypress Ctrl+R" is pressed. For ex.. consider #!/usr/bin/python import time print "Hello.. again" whi...

Create broken symlink with Python

Using Python I want to create a symbolic link pointing to a path that does not exist. However os.symlink just complains about "OSError: [Errno 2] No such file or directory:".. This can easily be done with the ln program, but how to do it in Python without calling the ln program from Python? Edit: somehow I really messed this up :/ ... b...

String formatting expressions (Python)

String formatting expressions: 'This is %d %s example!' % (1, 'nice') String formatting method calls: 'This is {0} {1} example!'.format(1, 'nice') I personally prefer the method calls (second example) for readability but since it is new, there is some chance that one or the other of these may become deprecated over time. Which do y...

len(object) or hasattr(object, __iter__) ?

Hi Pythonners ! (The following is python3-related (if that matter).) This this the code I've written (simplified) : class MyClass: def __init__(self): self.__some_var = [] @property def some_var(self): return self.__some__var @some_var.setter def some_var(self, new_value): if hasattr(new...

How to find unique starts of strings?

If I have a list of strings (eg 'blah 1', 'blah 2' 'xyz fg','xyz penguin'), what would be the best way of finding the unique starts of strings ('xyz' and 'blah' in this case)? The starts of strings can be multiple words. ...