How do I check for EOF in Python? I found a bug in my code where the last block of text after the separator isn't added to the return list. Or maybe there's a better way of expressing this function?
Here's my code:
def get_text_blocks(filename):
text_blocks = []
text_block = StringIO.StringIO()
with open(filename, 'r') as f...
I am building a website where I have a need that user should be able to evaluate some expression based from the value in DB tables, instead of using tools like pyparsing etc, I am thinking of using python itself, and have come up with a solution which is sufficient for my purpose. I am basically using eval to evaluate the expression and ...
import cherrypy
import os
PORT = 8080
class intelServ:
def index(self, botkey = None, userkey = None, network = None, user = None, channel = None, msg = None, step = None, **args):
# If any necessary parameters are missing, the bot should fail silently.
#if not botkey or not userkey or not network or not user or no...
My app must read an SSL url from a third party. How do I best store the third party credentials in my own database, which protects the third party credentials from being compromised? Consider both absolute security and practicality. One-way hashing the credentials is not useful as I must restore credentials to plaintext for the SSL call....
When __builtins__ is set and I try to access function globals, I get this error
>>> def f(): pass
...
>>> f.func_globals
{'f': <function f at 0x00B83270>, '__builtins__': <module '__builtin__' (built-in)>}
>>> __builtins__ = {}
>>> f.func_globals
Traceback (most recent call last):
File "<string>", line 1, in <string>
RuntimeError: re...
I used an anonymous pipe to capture all stdout,and stderr then print into a richedit, it's ok when i use wsprintf ,but the python using multibyte char that really annoy me. how can I convert all these output to unicode?
UPDATE 2010-01-03:
thanx for the reply. but, it seems the str.encode() only worked with print xxx stuff, if there is ...
s = set('ABC')
s.add('z')
s.update('BCD')
s.remove('DEF') # error here
s -= set('DEFG')
...
I'm thinking about good ways to store third party credentials, which basically means there needs to be a secret somewhere, either in code or data. I'm deploying on google app engine.
If the 'secret' was something like
pw_passphrase = sha2(username + 'global-password')
pw_plaintext = aes_decrypt(pw_passphrase, pw_ciphertext)
can I dep...
backend_dir = os.path.join(__path__[0], 'backends')
Why can't I find it?
...
I use grep to parse through my trading apps logs, but it's limited in the sense that I need to visually trawl through the output to see what happened etc.
I'm wondering if Perl is a better option? Any good resources to learn log and string parsing with Perl?
I'd also believe that Python would be good for this. Perl vs Python vs 'grep o...
my ide is 'ulipad'
and i open the file,it can't be Show,how can i get it.
...
Python seems to have functions for copying files (e.g. shutil.copy) and functions for copying directories (e.g. shutil.copytree) but I haven't found any function that handles both. Sure, it's trivial to check whether you want to copy a file or a directory, but it seems like a strange omission.
Is there really no standard function that w...
I want to start a thread when django project runserver successfully.
where can I put the create-thread-and-start code? Is there any hook for the django runserver?
...
Given a local directory structure of /foo/bar, and assuming that a given path contains exactly one file (filename and content does not matter), what is a reasonably fast way to get the filename of that single file (NOT the file content)?
...
Hello,
I am using a Dojo Textarea Dijit to input and submit text (to be processed).
I found that after submiting, if a browser back-button is pressed (IE8, Firefox) unlike regular HTML Textarea, I return to the input screen, but the Textarea is EMPTY.
What I would like to happen is that after back-button is pressed, I would return to ...
In theory, Dalvik executes any virtual machine byte code, created for example with the compilers of
AspectJ
ColdFusion
Clojure
Groovy
JavaFX Script
JRuby
Jython
Rhino
Scala
Are there already working versions of bytecode compilers for Dalvik available for other languages than Java?
...
hi,
ive download python 2.5 i just wanted to know is Tkinter include with python or is it a seprate download?
...
I'm having a problem reading and processing data from my server. I've spent hours debugging this and it seems as though the problem has nothing to do with the server but is really just an issue with one of my for loops. Its difficult to explain this without actually seeing the data from the server, but I'll do my best to explain this.
B...
For a NLP project of mine, I want to download a large number of pages (say, 10000) at random from Wikipedia. Without downloading the entire XML dump, this is what I can think of:
Open a Wikipedia page
Parse the HTML for links in a Breadth First Search fashion and open each page
Recursively open links on the pages obtained in 2
In ste...
Hi,
I've always thought about creating my own ftp client ever since I've started using the Internet. And now that I'm studying Python, I'm thinking about creating one as an exercises/personal project.
I'm wondering,
what libraries do you guys suggest?
Will ftplib suffice? Or would you
suggest another library(preferably
one that has ...