I am trying to this function:
def sleep(sec):
for i in range(sec):
print(".", end=" ");
time.sleep(1);
the problem is that it waits for the for loop to finish then it prints everything.
If I use the normal print with \n in the end everything works as it should. But with the end=" "
it does not.
...
I'm running this command in a Python script:
try:
print sql_string
cursor.execute(sql_string)
except:
print sys.exc_info()
and getting:
(<class 'psycopg2.InternalError'>, InternalError('current transaction is aborted, commands ignored until end of transaction block\n',), <traceback object at 0x1010054d0>)
However if I ...
I've been teaching myself Python at my new job, and really enjoying the language. I've written a short class to do some basic data manipulation, and I'm pretty confident about it.
But old habits from my structured/modular programming days are hard to break, and I know there must be a better way to write this. So, I was wondering if any...
As a hobby project, I had like to implement a Morse code encoder and decoder in C++ and Python (both). I was wondering the right data structure I should use for that. Not only is this question related to this specific project, but in general, when one has to make predefined text replacements, what is the best and the fastest way of doing...
I am trying to pass a string which has a '%' in it (its actually a sql query string). How do I pass the % (do I have to use a specific escape character?
eg:
compute_answertime("%how do I%")
...
I have a SocketServer.StreamRequestHandler server that calls self.rfile.readline() to read a request and then calls self.wfile.write(data) to send back some data:
class FileServerHandler(SocketServer.StreamRequestHandler):
def handle(self):
# self.rfile is a file-like oject created by the handler
data = self...
I was quite surprised when
[] is not []
evaluated to True.
What is happening in this code? What really not and is statements are doing?
...
I have a dictionary with keys and a list attached as value to each key.
I have to traverse list value attached to each key and segregate them into two different lists with '0' and '1' ( as '0' and '1' are the values in the list) also with the count of '0' , '1' and the total. Please let me know how should i go abut doing this. Thanks
...
Hello,
How can I set error reporting and warning outputs in Python like in PHP error_reporting(E_LEVEL)?
...
I would like to see what is best way to determine current script directory in python?
I discovered that two to the many ways of calling python code, it is hard to find a good solution.
Here are some problems:
__file__ is not defined if the script is executed with exec, execfile
__module__ is defined only in modules
Use cases:
./...
From what I understand, Pylons is more of a 'bare bones' framework (where you can choose your ORM and template engine), and Django is a little more rich in nature.
What exactly are the features/frameworky elements that Django has that Pylons doesn't?
(other than its own ORM, and its auto-admin page generation)
...
I am trying to convert this C code I have into a python script so it's readily accessible by more people, but I am having problems understanding this one snippet.
int i, t;
for (i = 0; i < N; i++) {
t = (int)(T*drand48());
z[i] = t;
Nwt[w[i]][t]++;
Ndt[d[i]][t]++;
Nt[t]++;
}
N is a value (sum of one column from an array...
I got the following message:
An unhandled win32 exception occurred in numpy-1.5.0-sse3.exe [3324].
The exception occurred in the Numpy installer for Python 2.7---I have the latter on the machine.
When I clicked "Yes" for using the selected debugger, I got the following message:
The Application Data folder for Visual Studio could not ...
Has anyone managed successfully using cscope with Python code? I have VIM 7.2 and the latest version of cscope installed, however it doesn't get my code's tags correctly (always off by a couple of lines). I tried the pycscope script but its output isn't supported by the modern version of cscope.
Any ideas? Or an alternative for browsing...
Python has many GUI toolkits. If I understand correctly, these toolkits typically take on the responsibility of rendering their own widgets (rather than relying on the operating system). This achieves cross-platform support at the cost of having widgets that don't necessarily look, feel and behave exactly like their native counterparts. ...
i am into a project where zope web server is used. With this Posgresql database is used. But i am not able to add a new Posgresql connection via zope??? Actually, i am a beginner and i am not aware of what else i need to install so that i can use Posgresql dB with zope. From whatever i have explored about this i have come to know that i ...
I'm trying to collect some of my default settings, and one thing I realized I don't have a standard for is .gitignore files. There's a great thread showing a good .gitignore for Visual Studio projects, but I don't see many recommendations for Python and related tools (PyGTK, Django).
So far, I have...
*.pyc
*.pyo
...for the compiled ...
How should I compute log to the base 2 in python. Eg. I have this equation where i am using log base 2
import math
e = -(t/T)* math.log((t/T)[, 2])
...
Hello All. I'm currently trying to wrap my head around learning Python and I've come to a bit of a stall at recursive functions. In the text I'm using (Think Python), one of the exercises is to write a function that determines if number a is a power of number b using the following definition:
"A number, a, is a power of b if it is di...
This is the code that lists all the subdirectories from FTP server. How do I search for the most recent Excel files sitting in these multiple Subdirectories directory? As shown in the results, I want to go through all the ls**** subdirectories and notify me if there is an Excel file with today's date.
Thanks in advance!
from ftplib i...