Forum: Python 3 Hours Ago |
| Replies: 14 Views: 187 You can also do this without a loop
#!/usr/bin/env python
import re
nonletters = re.compile("[^a-zA-Z]+")
def letters_only(mystring):
return nonletters.sub(lambda m: '', mystring) |
Forum: Python 6 Hours Ago |
| Replies: 3 Views: 79 If you have 10 file1 and 2000 file2, it makes 20000 file3 (output files). You should explain clearly what you want:
* Are the file1 in a separate directory ? How do you recognize that a file is a... |
Forum: Python 8 Hours Ago |
| Replies: 3 Views: 79 I think you could try something like this
def key(line):
return tuple(line.strip().split()[2:6])
def make_key_set(file_path):
return set(key(line) for line in open(file_path))
... |
Forum: Python 11 Hours Ago |
| Replies: 8 Views: 90 You must CALL the read method to get the file's content
text = foo.read()
Also please mark your other thread with the same error as solved. |
Forum: Python 12 Hours Ago |
| Replies: 8 Views: 90 The statement
special = re.compile(r"[etn]")
creates a regular expression object, which represents the set of characters 'e', 't' or 'n'. When
special.sub(escape, text)
is executed, all... |
Forum: Python 12 Hours Ago |
| Replies: 8 Views: 90 You can use regular expressions and the re.sub function, like this
import re
special = re.compile(r"[etn]")
def escape(match):
return "\\" + match.group(0)
if __name__ == "__main__": |
Forum: Python 14 Hours Ago |
| Replies: 1 Views: 82 You MUST NOT install packages using source code and "./configure, make, make install". It's the last resort for programs for which no mandriva package exist. The correct way to do it is to install... |
Forum: Python 20 Hours Ago |
| Replies: 3 Views: 82 When you open a file, the cursor is at the beginning of the file. However
myfile.seek(0)
goes to the beginning of the file. Finally, read this.... |
Forum: Python 23 Hours Ago |
| Replies: 4 Views: 90 First, you must read this reference counting (http://docs.python.org/extending/extending.html#reference-counting-in-python).
Why do you need to incref results ? First argument, that's how code is... |
Forum: Python 23 Hours Ago |
| Replies: 4 Views: 90 Yes I think that you must always incref the results. Also consider using Py_XINCREF and Py_XDECREF which handle the case where you pass a null pointer.
A good idea is to test your code with the help... |
Forum: Python 1 Day Ago |
| Replies: 17 Views: 298 If you want a link to a tutorial, here is one (http://wiki.mandriva.com/en/Docs/Basic_tasks/Installing_and_removing_software#Making_more_applications_available). You should browse the mandriva... |
Forum: Python 1 Day Ago |
| Replies: 6 Views: 158 In fact, there is a simpler method
def remove_all(sub, s):
"""
>>> remove_all('an', 'banana')
'ba'
>>> remove_all('cyc', 'bicycle')
'bile'
>>> remove_all('iss', 'Mississippi')
'Mippi' |
Forum: Python 1 Day Ago |
| Replies: 6 Views: 158 A possible implementation of remove_all
import re
def remove_all(sub, s):
"""
>>> remove_all('an', 'banana')
'ba'
>>> remove_all('cyc', 'bicycle')
'bile' |
Forum: Python 2 Days Ago |
| Replies: 17 Views: 298 I don't know how to solve the mirrorlist problem. Normally you dont need to insert the DVD, but if you insert it I don't think it hurts.
You can attach images to posts.
I soon must go for a few... |
Forum: Python 2 Days Ago |
| Replies: 17 Views: 298 selec tfull set of sources |
Forum: Python 2 Days Ago |
| Replies: 17 Views: 298 When you build python3 form sources, it's installed in /usr/local. There is no risk of conflict. |
Forum: Python 2 Days Ago |
| Replies: 17 Views: 298 Did you try to click on the "add" button in your last picture ? |
Forum: Python 2 Days Ago |
| Replies: 4 Views: 160 Did you read this in your assingment ?
Although it can be helpful to you to discuss your program with other people, and that is a reasonable thing to do
and a good way to learn, the work you hand... |
Forum: Python 2 Days Ago |
| Replies: 17 Views: 298 Also note that it should be available soon, as this page (http://fr2.rpmfind.net/linux/rpm2html/search.php?query=tkinter3) proves. But I don't think you should try to install these packages on 2009... |
Forum: Python 2 Days Ago |
| Replies: 17 Views: 298 I said that you need libtk-devel and libtcl-devel if you want to build with tkinter. If the libraries don't show in the list, you must check that your rpm sources configuration is good: open the... |
Forum: Python 3 Days Ago |
| Replies: 4 Views: 116 It already exists (py >= 2.6)
from itertools import product
myproduct = set(product(myset1, myset2)) |
Forum: Python 5 Days Ago |
| Replies: 0 Views: 138 Some time ago, I was writing a small command line interpreter, with the help of the standard module cmd (http://docs.python.org/library/cmd.html#module-cmd) which offers minimal support for such... |
Forum: Python 5 Days Ago |
| Replies: 17 Views: 298 In the applications menu of your desktop panel, you select install software (you need the root password for this). This opens the software manager, which has a search form. Put libtcl in the search... |
Forum: Python 5 Days Ago |
| Replies: 9 Views: 206 There are small differences, for example in Pickle, there are Pickler and Unpickler classes which don't exist in cPickle. Often such double implementations exist because someone first wrote a python... |
Forum: Python 5 Days Ago |
| Replies: 9 Views: 206 The standard library has examples of modules wich offer 2 implementations, a C and a pure python implementation. For example Pickle and cPickle and StringIO and cStringIO. For most problems, you can... |
Forum: Python 5 Days Ago |
| Replies: 17 Views: 298 You probably need at least libtk-devel and libtcl-devel to build with tkinter. |
Forum: Python 5 Days Ago |
| Replies: 9 Views: 206 I think it's only the terminology of the python documentation. Usually the documentation opposes 'user defined types' implemented in python to 'built in types' implemented in C. |
Forum: Python 5 Days Ago |
| Replies: 9 Views: 206 There are many examples of extensions written in C or C++. For example the numpy package implements classes written in C.
One of the main reasons to do this is that C or C++ run much faster than... |
Forum: Python 5 Days Ago |
| Replies: 3 Views: 180 I don't understand the content of the function parse1. To use strcat, you must make sure that the destination char* is large enough to hold the result. I donc think that you can pass a python string... |
Forum: Python 6 Days Ago |
| Replies: 3 Views: 180 Did you try
print(charp_getitem(d, 20))
? |
Forum: C 6 Days Ago |
| Replies: 6 Views: 218 I looked in the source code of gcc-4.3.2 and I found this
char **buildargv (const char *input)
{
char *arg;
char *copybuf;
int squote = 0;
int dquote = 0;
int bsquote = 0;
int... |
Forum: C 6 Days Ago |
| Replies: 6 Views: 218 Thanks for your replies. I think you're right, there are some functions related to this in OS source code, but they're not very useful. It would have been great to find a well known C function for... |
Forum: C 6 Days Ago |
| Replies: 6 Views: 218 Suppose that I have a program named myprog, and I type this in a shell
$ myprog -z hello -m "this is a message"
The function main in myprog will receive a char** argv containing the following... |
Forum: Python 6 Days Ago |
| Replies: 3 Views: 120 try
string2 = "Random Number is\n{value:^16}".format(value = string1)
Also, you can read this (http://www.daniweb.com/code/snippet232375.html) :) |
Forum: Python 6 Days Ago |
| Replies: 7 Views: 204 In the "if choice" sequence, you should replace raw_input by input because you want the user input to be interpreted as a number and not as a string. Also read this... |
Forum: Python 7 Days Ago |
| Replies: 2 Views: 130 You can enter a python list and then convert it using eval
userInput = input("Enter a python list: ")
mylist = eval(userInput.strip())
# check that it's a list
assert(isinstance(mylist,... |
Forum: Python 7 Days Ago |
| Replies: 3 Views: 204 A nice tool is sphinx (http://sphinx.pocoo.org/) which converts text written in rich text format to html. |
Forum: Python 7 Days Ago |
| Replies: 5 Views: 208 I discovered a new python book today http://www.linuxtopia.org/online_books/programming_books/python_programming/index.html. |
Forum: Python 7 Days Ago |
| Replies: 8 Views: 196 I suggest that you write a module
# mystartup.py
import os, sys
site_packages = os.path.join(os.path.split(os.__file__)[0], "site-packages")
sys.path.append(site_packages)
and put this... |
Forum: Python 8 Days Ago |
| Replies: 12 Views: 694 Formatting with colors in a linux console
The following module combines formatting strings and ansi escape sequences to support printing with color in a linux console. After importing the module,... |