Search Results

Showing results 1 to 40 of 93
Search took 0.02 seconds.
Search: Posts Made By: Gribouillis
Forum: Python 6 Days Ago
Replies: 4
Views: 273
Posted By Gribouillis
There are 2 small bugs in the previous post: remove the line location = sys.argv[-1] in function print_disk_info. Also in hardpath(), the call os.readlink(p) should be replaced by _readlink(p) where...
Forum: Python 9 Days Ago
Replies: 2
Views: 172
Posted By Gribouillis
I think it maintains the traditional distinction between allocation and initialization. When you use structures in C for example, you must first use malloc to allocate a structure and then you...
Forum: Python 9 Days Ago
Replies: 19
Views: 505
Posted By Gribouillis
You can get a drive letter from a path like this

import os
drive = os.path.splitdrive(mypath)[0]
print(drive)

Now for mypath, you could use either the current working dir os.getcwd() or your...
Forum: Python 11 Days Ago
Replies: 5
Views: 260
Posted By Gribouillis
You can speed this up:

def sine(x):
term = float(x)
result = term # avoid 'sum' which is the name of a builtin function
u = - term * term # this is minus (x squared)
n = 0 #...
Forum: Python 12 Days Ago
Replies: 4
Views: 235
Posted By Gribouillis
You probably still have the wrong indentation for the line
status = staticmethod(status).
Forum: Python 12 Days Ago
Replies: 13
Views: 384
Posted By Gribouillis
I see. Note that handling errors by the means of a return status is not very pythonic. It's a C like way of thinking. A more pythonic approach would be to define a

class LibraryError(Exception):...
Forum: Python 12 Days Ago
Replies: 4
Views: 235
Posted By Gribouillis
The indentation is bad. The code should read

# Classy Critter
# Demonstrates class attributes and static methods

class Critter(object):
"""A virtual pet"""
total = 0
Forum: Python 12 Days Ago
Replies: 13
Views: 384
Posted By Gribouillis
Nice. Just one criticism, I don't like your

except:
return False

because you're just hiding errors, so that if something goes wrong, your program will never know. You should think about...
Forum: Python 12 Days Ago
Replies: 13
Views: 384
Posted By Gribouillis
I prefer design 1. We don't know anything about the algorithms that you have in mind, so there is no obvious benefit for introducing the classes Search and Edit. With design 1, the Library object...
Forum: Python 16 Days Ago
Replies: 5
Views: 270
Posted By Gribouillis
I modified your code so that it prints the file name and the destination name instead of renaming the file. Run it and modifiy it until it gives the correct values, then uncomment the 'rename' line....
Forum: Python 18 Days Ago
Replies: 7
Views: 7,145
Posted By Gribouillis
You can write

from os.path import join as pjoin
targetfolder = raw_input('enter a target folder:\n').strip()
newname = raw_input('enter a new base name:\n')
newname = pjoin(targetfolder,...
Forum: Python 21 Days Ago
Replies: 5
Views: 340
Posted By Gribouillis
Google found a patch for scapy.all..sniff, wich allows to stop the sniff function programmatically. You should try this http://trac.secdev.org/scapy/wiki/PatchSelectStopperTimeout
Forum: Python 23 Days Ago
Replies: 6
Solved: drawing an eye?
Views: 287
Posted By Gribouillis
You can write

if colour in ("Green", "Blue", "Red"):
... # do something
else:
... # do something else
Forum: Python 24 Days Ago
Replies: 9
Views: 316
Posted By Gribouillis
Note that in python 3, there are no 'old style class', so that your class is implicitely a subclass of object. Here is a small experiment with python 2.6 and python 3.1

Python 2.6.4 (r264:75706,...
Forum: Python 25 Days Ago
Replies: 14
Views: 596
Posted By Gribouillis
Is this what you mean ?

class Agent:
def __init__(self):
exec "import random" in self.__dict__


ag = Agent()

print ag.random.randrange(100) # this works
Forum: Python 25 Days Ago
Replies: 7
Views: 255
Posted By Gribouillis
It's true, suppose that mypackage contains __init__.py, foo.py, bar.py and baz.py. You could have this in __init__.py

import foo
import bar
import baz

then, if you simply write import...
Forum: Python 32 Days Ago
Replies: 8
Views: 273
Posted By Gribouillis
I ran pylint (http://www.logilab.org/project/pylint) on this code. Here is the result (note that this depends on my personal configuration of pylint, it may give a different result on your system)
...
Forum: Python 33 Days Ago
Replies: 4
Views: 235
Posted By Gribouillis
You can also use format

message = "z's value is {z:0{digits}n}".format(z=2, digits=3)
print(message)
Forum: Python 34 Days Ago
Replies: 6
Views: 373
Posted By Gribouillis
Here is a script which should work for 1 .pdb file and many .pd files. It creates the new versions of the .pd files (with less lines) in a separate output directory. See the usage at the end of the...
Forum: Python Nov 3rd, 2009
Replies: 3
Views: 194
Posted By Gribouillis
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 Nov 2nd, 2009
Replies: 4
Views: 229
Posted By Gribouillis
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 Oct 30th, 2009
Replies: 18
Views: 518
Posted By Gribouillis
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 Oct 30th, 2009
Replies: 9
Views: 287
Posted By Gribouillis
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 Oct 30th, 2009
Replies: 9
Views: 287
Posted By Gribouillis
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 Oct 30th, 2009
Replies: 9
Views: 287
Posted By Gribouillis
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 Oct 30th, 2009
Replies: 9
Views: 287
Posted By Gribouillis
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: C Oct 29th, 2009
Replies: 6
Views: 333
Posted By Gribouillis
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: Python Oct 29th, 2009
Replies: 3
Views: 180
Posted By Gribouillis
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 Oct 27th, 2009
Replies: 5
Views: 368
Posted By Gribouillis
I discovered a new python book today http://www.linuxtopia.org/online_books/programming_books/python_programming/index.html.
Forum: Python Oct 25th, 2009
Replies: 9
Views: 351
Posted By Gribouillis
:) :) :) :) :) :) :)
Forum: Python Oct 25th, 2009
Replies: 2
Views: 323
Posted By Gribouillis
This should work

value = min(x for x in temperature_sequence if x > 0)

Note: this raises ValueError if all temperatures are below 0.
Forum: Python Oct 22nd, 2009
Replies: 12
Views: 1,322
Posted By Gribouillis
The floating point precision can be passed as argument too

rabbits = {
"flopsy" : 1.0/3, "mopsy" : 576.0/7, "cotton tail": .76/5, "peter": 300000.0/37,
}

nwidth = 1 + max(len(name) for...
Forum: Python Oct 22nd, 2009
Replies: 12
Views: 1,322
Posted By Gribouillis
Same example with computed field's width:

rabbits = {
"flopsy" : 1.0/3, "mopsy" : 576.0/7, "cotton tail": .76/5, "peter": 300000.0/37,
}

nwidth = 1 + max(len(name) for name in rabbits)
...
Forum: Python Oct 22nd, 2009
Replies: 12
Views: 1,322
Posted By Gribouillis
The syntax of the str.format() method described in the python 2.6 documentation (http://docs.python.org/library/string.html#formatstrings) looks both powerful and complex. The idea of this thread is...
Forum: Python Oct 21st, 2009
Replies: 2
Views: 236
Posted By Gribouillis
s='1234444432187667890000568984'
print("\n".join(("I found %d: %d" % (s.count(str(i)), i)) for i in range(10)))
Forum: Python Oct 20th, 2009
Replies: 4
Views: 217
Posted By Gribouillis
I wrote a code snippet (http://www.daniweb.com/code/snippet217111.html) for this last year :)
Forum: Python Oct 20th, 2009
Replies: 4
Views: 315
Posted By Gribouillis
Ok, you can change the text with

l.setText(str(300)) # the text now shows 300

note that the letter 'l' is a bad variable name. Good variable names have at least 3 characters (except for loop...
Forum: Python Oct 19th, 2009
Replies: 13
Views: 501
Posted By Gribouillis
I think I understand your point now. There must be a limitation somewhere when n is large. However, note that the builtin shuffle function takes an optional argument 'random' which allows you to pass...
Forum: Python Oct 19th, 2009
Replies: 8
Solved: List help...
Views: 219
Posted By Gribouillis
A shorter method

L1=[[1,2,3],[4,5,6],[7,8,9],[10,11,12]]
L2=[1,2,3,4,11]

set2 = set(L2)
L3 = [x for x in L1 if set2.intersection(x)]
print(L3)
Forum: Python Oct 18th, 2009
Replies: 6
Views: 308
Posted By Gribouillis
you should use getattr(random, name)
Showing results 1 to 40 of 93

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC