2,646 Posted Topics

Member Avatar for vegaseat

I got closest_pair1(mylist) = 0.000008 seconds closest_pair2(mylist) = 0.000038 seconds closest_pair3(mylist) = 0.000040 seconds closest_pair4(mylist) = 0.000010 seconds closest_pair5(mylist) = 0.000041 seconds with an AMD Athlon(tm) X2 245 Processor

Member Avatar for Lardmeister
5
756
Member Avatar for bintony.ma_1

You can also try to read the file by chunks import io MB = 1 << 20 # read the file by chunks of 64 megabytes with io.open('input.txt', mode="r+b", buffering = 64 * MB) as infile: # etc

Member Avatar for bintony.ma_1
0
454
Member Avatar for prashanth s j

> dear list i am new to python and write few basic programs in python now i want learn multithrading in pyhton , can anyone please provide me some link or guidance , how to go through it. Start by reading [python module of the week: threading](http://blog.doughellmann.com/2008/01/pymotw-threading_13.html).

Member Avatar for Gribouillis
0
346
Member Avatar for lycanickel

In your code, `num` is a string, and `numin` is an integer. It means that the arithmetic expressions involving `num` won't work as expected. The best thing to do is to replace line 2 with `num = int(num)` and forget about `numin`. You can even write `num = int(num) % …

Member Avatar for Gribouillis
0
374
Member Avatar for bobys

Your input window is idle's shell window. There is an option to change the title of the shell window when you start idle. Start idle with idle -t "Python input" from a terminal.

Member Avatar for bobys
0
331
Member Avatar for krystosan

Because this call invokes an underlying C++ function which uses argv and doesn't know about python. Qt understand a set of command line arguments, see [here](http://doc.qt.digia.com/qt/qapplication.html#QApplication) for example.

Member Avatar for Gribouillis
0
2K
Member Avatar for eternalcomplex

> How does python know that card must be of class Card? Python does not know. You could add anything with this method. There is no type checking at run time. What you could do is add an assert statement def add_card(self, card): assert isinstance(card, Card) return self.hand.append(card)

Member Avatar for TrustyTony
0
481
Member Avatar for don.davis.773

If you don't want to generate the page dynamically, you can generate it once a week and store an html file when you run your script. You could use a template engine like Mako for variable substitution in the html file. It is very easy to do.

Member Avatar for Gribouillis
0
205
Member Avatar for crashhold

I would try a single regular expression pat = r"(?:\d{1,2}(?:(?:(?: \w{3})? - \d{1,2})? )?(?:\w{3} \d{4}))" I don't know about the mongodb part. Use kodos to debug python regexes.

Member Avatar for Gribouillis
0
323
Member Avatar for ashley9210

Hint: if there is a vertex at a point `(x0, y0)`, the other vertices are at points x, y = (x0+ a * i + b * j, y0 + c * j) where `a, b, c` are 3 given numbers and `i, j` are varying integers.

Member Avatar for Gribouillis
0
147
Member Avatar for krystosan

A reason could be that the programmer wants the Asset to be a dictionary, and at the same time he/she wants to add asset-specific behavior to this dictionary. To do so, he/she subclasses the built-in `dict` class. I don't think adding the properties name, scene, show, image is a very …

Member Avatar for krystosan
0
171
Member Avatar for elrond

Start with some code for the > ask the user-for year month and date part, you need the `input()` function (in python 3) or `raw_input()` (in python 2).

Member Avatar for Lardmeister
-1
125
Member Avatar for BigPaw
Member Avatar for Lardmeister
0
270
Member Avatar for krystosan
Member Avatar for krystosan
0
145
Member Avatar for Bluescreendeath

Use the fractions module >>> from fractions import Fraction >>> day = 23 + Fraction(56, 60) >>> day Fraction(359, 15) >>> 60 * day * 7 Fraction(10052, 1)

Member Avatar for Gribouillis
0
240
Member Avatar for Gribouillis

This python 2.7 snippet adds a thin layer of sugar on the itertools module's api, allowing many of its functions to be used as decorators and adding some new functions. Enjoy !

Member Avatar for Gribouillis
3
331
Member Avatar for vegaseat

Here is how to display the base64 image using tkinter and PIL in python 2 if __name__ == "__main__": from StringIO import StringIO import Tkinter from PIL import ImageTk, Image root = Tkinter.Tk() #root.bind("<Button>", lambda event: event.widget.quit()) root.geometry('+%d+%d' % (100,100)) f = StringIO(base64.decodestring(str(rainbow_jpg_b64))) image = Image.open(f) zoom = 5 image …

Member Avatar for HiHe
5
8K
Member Avatar for shayallenhill

I suggest using a [cached property](http://www.daniweb.com/software-development/python/code/217241/a-cached-property-decorator) class HoldAttr(object): @cached_property def foundat(self): return [] @property def was_found(self): return "foundat" in self.__dict__ if __name__ == "__main__": h = HoldAttr() for i in range(3): h.foundat.append(i) print(h.foundat) print(h.was_found) h = HoldAttr() print(h.was_found) """ my output --> [0, 1, 2] True False """ However, a …

Member Avatar for hughesadam_87
0
431
Member Avatar for drichird
Member Avatar for drichird
0
250
Member Avatar for MissAuditore

Read the csv module's documentation! Here, you need at least to pass `delimiter=';'` to `csv.reader()`. If necessary, play with dialects and formatting parameters until you get the correct result.

Member Avatar for HiHe
0
236
Member Avatar for jworld2

A good way to do this is to have a folder for your python modules and to set the environment variable PYTHONPATH to contain this folder. If you're on windows, search for environment variables in windows help and set the correct value. In this folder, you can create files like …

Member Avatar for vegaseat
0
5K
Member Avatar for elbarto

Hello, I don't use 3D myself, but I have a few links: [mayavi](http://docs.enthought.com/mayavi/mayavi/) [collection of links](http://www.vrplumber.com/py3d.py) [freecad](http://sourceforge.net/projects/free-cad/) [vpython](http://www.vpython.org/) I hope they will help you find your solution.

Member Avatar for TrustyTony
0
2K
Member Avatar for DustinS

[This post](http://stackoverflow.com/questions/405058/line-reading-chokes-on-0x1a) says to open the file in mode 'rb' or 'rU'.

Member Avatar for Gribouillis
0
2K
Member Avatar for shanenin

There is a way to ask python what are start, stop and step: >>> s = slice(None, None, -2) # a slice object corresponding to [::-2] >>> s.indices(8) (7, -1, -2) # start, stop, step if the slice is applied to a tuple of length 8

Member Avatar for shanenin
0
1K
Member Avatar for Inshu

It means that a function tried to call an attribute getitem on a float object, like this code >>> x = 3.14 >>> x.getitem Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'float' object has no attribute 'getitem' Here are similar errors >>> x = 3.14 …

Member Avatar for Lardmeister
0
753
Member Avatar for pauldespre

> Can you explain me shortly how that if statement works? When a python file `foo.py` is executed, a variable `__name__` is inserted in its namespace. If `foo.py` is ran as the main script, the value of this variable is the string `"__main__"`. If instead `foo.py` is imported from another …

Member Avatar for TrustyTony
0
147
Member Avatar for La:)

Start by making a list containing the lengths of the 1000 sequences. Tony is right, we're dying to see the code.

Member Avatar for abc0502
0
1K
Member Avatar for barrelr0ll

Add `return p_num` at the end of the function. Your function currently returns `None`. The `p_num` inside the function is not the same as the p_num outside the function (because it appears in the left part of assignment statements). It is a local variable. You need a return statement to …

Member Avatar for barrelr0ll
0
95
Member Avatar for Inshu
Member Avatar for Inshu
0
115
Member Avatar for syeda amna

[See the light](http://docs.python.org/using/windows.html) with python guru Mark Hammond.

Member Avatar for syeda amna
1
585
Member Avatar for weblover

This should work def funcdist(myvar): return [[ sum(1 for (a, b) in zip(line_a, line_b) if a != b) for line_b in myarr] for line_a in myarr ] The problem in your snippet, is that a new testarr needs to be created in the hx loop. Replace line 6 by line …

Member Avatar for weblover
0
372
Member Avatar for hughesadam_87

Yes it is possible: a, b = zip(*(((item*10),(item*20)) for item in items)) but it gives tuples instead of lists. If you want lists, you can write a, b = (list(x) for x in zip(*(((item*10),(item*20)) for item in items))) another way is a, b = (list(item * x for item in …

Member Avatar for hughesadam_87
0
179
Member Avatar for glenwill101

The other solution is to add `shell = True` to `subprocess.call()`'s arguments.

Member Avatar for Gribouillis
0
127
Member Avatar for padton

You can go one step further and write for i in range(3): for w,x,y,z in zip(*(v.values for v in (ar[i+1], br[i+1], ar[i], br[i]))): val = (sqrt((w.data**2)+(x.data**2)))-(sqrt((y.data**2)+(z.data**2))) files[i].write(('%6.20f\n') % (val)) provided you define lists `ar` and `br` containing `[ar0, ar1, ar2, ar3]` etc instead of variables whith numbered names.

Member Avatar for Gribouillis
0
232
Member Avatar for compscihelp

Compute `isomorphic(nestA, nestB)` by hand without a computer and note carefully every single step of your reasonning. This will give you pseudo code. Then write the pseudo code, then implement.

Member Avatar for compscihelp
0
205
Member Avatar for echocoder

Your class should read class Environment(object): def __init__(self,rowCount,columnCount): self.env = [[ None for i in range(columnCount)] for j in range(rowCount) ] def setElement(self, row, column, value = 0): self.env[row][column] = value def getElement(self, row, column): return self.env[row][column] myenv = Environment(6, 6) # create an instance myenv.setElement(2, 2) myenv.setElement(3, 4, 1000) …

Member Avatar for echocoder
0
1K
Member Avatar for kogia
Member Avatar for whoisstanley
Member Avatar for Lardmeister
0
185
Member Avatar for Gribouillis

This snippet defines a `dir()` function which extends python's builtin `dir()` function by adding options to filter the returned sequence of strings by the means of regular expressions. The main use case is live inspection of python objects and modules during an interactive session with the python interpreter. The idea …

Member Avatar for TrustyTony
2
502
Member Avatar for rrn8

Use [this snippet](http://www.daniweb.com/software-development/python/code/257449/a-command-class-to-run-shell-commands) and write com = Command("cat /tmp/file.txt | grep ListenPort | awk -F").run() if com.failed: print com.error else: print com.output (correct the end of th awk command if necessary)

Member Avatar for rrn8
0
321
Member Avatar for hughesadam_87

I would try the root solvers in [scipy.optimize](http://docs.scipy.org/doc/scipy/reference/optimize.html) first (like scipy.optimize.fsolve or scipy.optimize.bisect, etc...). Theoretically speaking, this problem depends mainly on the monotonicity properties of the values in your array. Are they increasing or decreasing values, or randomly chosen values (or something else?). These properties should govern your strategy. For …

Member Avatar for hughesadam_87
0
165
Member Avatar for hughesadam_87

Usually, I'm using [this cached_property decorator](http://www.daniweb.com/software-development/python/code/217241/a-cached-property-decorator). Perhaps you could me more specific about your problem. A property usually means a computed attribute. I don't see an instance or an attribute in your post above, so you may be looking for something else.

Member Avatar for hughesadam_87
0
244
Member Avatar for bintony.ma
Member Avatar for bintony.ma_1
0
467
Member Avatar for crag0

The third item in os.walk is a list of filenames. Otherwise, the md5 of a file refers to the content of the file, not to the filename. Run your code before posting issues!

Member Avatar for crag0
0
326
Member Avatar for techyworld

It's impossible. How can you tell if 101110 means 10 11 10 or 101 110 ? What you can do is format every char with 3 digits >>> c = "\x0a" >>> ord(c) 10 >>> str(ord(c)) '10' >>> "{0:0>3}".format(ord(c)) '010'

Member Avatar for vegaseat
0
278
Member Avatar for anishxx323

Line 7 should go before the for loop. When it is executed, scores becomes a new empty list. Also line 10 should be `scores[:] = []`, otherwise it does nothing. It is better to write all the function definitions out of the for loop (before the loop). A function definition …

Member Avatar for TrustyTony
0
273
Member Avatar for nerdnapster

Well, you have >>> import os >>> filename = "foo/bar/baz/qux.naps" >>> name = os.path.basename(filename) >>> name 'qux.naps' >>> base, extension = os.path.splitext(name) >>> base 'qux' >>> extension '.naps' and also >>> os.path.exists(filename) # check if file exists False # or >>> os.path.isfile(filename) # check if a regular file with that …

Member Avatar for nerdnapster
0
127
Member Avatar for nerdnapster

You need a `return` statement. Also, I deduce from your print statement that you're using python 2 where raw_input should be used instead of input, so it will be def comein(string): return raw_input(string)

Member Avatar for nerdnapster
0
121
Member Avatar for techyworld

I don't know what this variable `infile` is, but it's not `rfile` nor `rfile1`. In the same way, why do you read the first file with `read()` and the last one with `readlines()` ? The 2 functions return different datatypes. Files are better opened with the `with` construct: with open('original.txt', …

Member Avatar for techyworld
0
367
Member Avatar for cruze098

One way to use class 1's methods in class 2 is to have a class 2 object *aggregate* a class 1 instance. It is a standard pattern in OOP, called composition, which is often used as an alternative to inheritance class Class1(object): def method(self): print(self) class Class2(object): def __init__(self): self.obj1 …

Member Avatar for Gribouillis
0
159

The End.