Hi all,
I'm trying to store in a variable the name of the current file that I've opened from a folder...
How can I do that?
I've tried cwd = os.getcwd() but this only gives me the path of the folder, and I need to store the name of the opened file...
Can you please help me?
Thanks.
...
Question so easy that fitted in the title :)
Eclipse (pydev): Is it possible to assign a shortcut to send selection to the python console?
...
I occasionally see the list slice syntax used in Python code like this:
newList = oldList[:]
Surely this is just the same as:
newList = oldList
Or am I missing something?
...
Is there a way to access a list(or tuple, or other iterable)'s next, or previous element while looping through with for loop?
l=[1,2,3]
for item in l:
if item==2:
get_previous(l,item)
...
This code
select.select([sys.stdin], [], [], 1.0)
does exactly what I want on Linux, but not in Windows.
I've used kbhit() in msvcrt before to see if data is available on stdin for reading, but in this case it always returns 0. Additionally msvcrt.getch() returns '\xff' whereas sys.stdin.read(1) returns '\x01'. It seems as if the m...
I have a program that can have a lot of parameters (we have over +30 differents options).
Example:
myProgram.exe -t alpha 1 -prod 1 2 -sleep 200
This is 3 Commands (from command pattern object at the end) that each contain some parameters. Inside the code we parse all command (start with -) and get a list of string (split all space) fo...
Is it possible to terminate a running thread without setting/checking any flags/semaphores/etc.?
...
Imagine I have the following:
inFile = "/adda/adas/sdas/hello.txt"
# that instruction give me hello.txt
Name = inFile.name.split("/") [-1]
# that one give me the name I want - just hello
Name1 = Name.split(".") [0]
Is there any chance to simplify that doing the same job in just one expression?
...
I am currently the following code based on Chapter 12.5 of the Python Cookbook:
from xml.parsers import expat
class Element(object):
def __init__(self, name, attributes):
self.name = name
self.attributes = attributes
self.cdata = ''
self.children = []
def addChild(self, element):
self.chi...
Hi,
I have the following problem:
# line is a line from a file that contains ["baa","beee","0"]
line = TcsLine.split(",")
NumPFCs = eval(line[2])
if NumPFCs==0:
print line
I want to print all the lines from the file if the second position of the list has a value == 0.
I print the lines but after that the following happe...
In C++ often do something like this:
typedef map<int, vector<int> > MyIndexType;
Where I then use it like this:
MyIndexType myIndex;
for( ... some loop ...)
{
myIndex[someId].push_back(someVal);
}
If there was no entry in the map the code will insert a new empty vector and then append to it.
In Python it would look like this:
m...
I'm using jython 2.2.1, and jdbc 1.2 and connecting to a mssql 2000 database, writing the contents of an email to it. When I get to the body of the email which can be quite large sometimes I need to truncate the data at 5000 chars. Except mssql & jdbc gang up on me like school yard bullies, when i check the database loads of my data is m...
I am having difficulty determining if the body of a text email message is base64 encoded.
if it is then use this line of code;
making use of jython 2.2.1
dirty=base64.decodestring(dirty)
else continue as normal.
This is the code I have atm. What line of code will allow me to extract this from the email:
"Content-Transfer-Encoding...
Writing a python script and it needs to find out what language a block of code is written in. I could easily write this myself, but I'd like to know if a solution already exists.
Pygments is insufficient and unreliable.
...
I've a python script that has to launch a shell command for every file in a dir:
import os
files = os.listdir(".")
for f in files:
os.execlp("myscript", "myscript", f)
This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python script.
How can I do? Do ...
Hi
I have a few Munin plugins which report stats from an Autonomy database. They all use a small library which scrapes the XML status output for the relevant numbers.
I'm trying to bundle the library and plugins into a Puppet-installable RPM. The actual RPM-building should be straightforward; once I have a distutils-produced distfile I...
So I'm looking for a pretty basic library in python where i can create a window, and then draw lines and basic shapes too it. Nothing too complex, just nice and simple. I figure theres lots of libraries out there that can do this, but I don't know any of them. Can anyone give me some recommendations?
Thanks
EDIT: Note that there are se...
I have around 20 or so active blogs that get quite a bit of spam. As I hate CAPCHA the alternative is very smart spam filtering. I want to build a simple REST api like spam checking service which I would use in all my blogs. That way I can consolidate IP blocks and offload spam detection to 3rd party such as Akisment, Mollom, Defensio ...
I have a string with a length that is a multiple of 8 that contains only 0's and 1's. I want to convert the string into a byte array suitable for writing to a file. For instance, if I have the string "0010011010011101", I want to get the byte array [0x26, 0x9d], which, when written to file, will give 0x269d as the binary (raw) contents...
I have a python module that defines a number of classes:
class A(object):
def __call__(self):
print "ran a"
class B(object):
def __call__(self):
print "ran b"
class C(object):
def __call__(self):
print "ran c"
From within the module, how might I add an attribute that gives me all of the classes?
...