2,646 Posted Topics

Member Avatar for krystosan
Member Avatar for rwe0

Startpage led to [this blog entry](https://medium.com/p/f2fa442daf99). Perhaps you have lxml on one OS and not on the other.

Member Avatar for rwe0
0
402
Member Avatar for krystosan

Did you check that the coverage module is installed ? $ pydoc coverage In linux mint, coverage is available via the package `python-coverage` .

Member Avatar for krystosan
0
563
Member Avatar for happygeek

People don't seem to run away from python. See this popularity comparison [url]http://langpop.com/[/url] for example. The only version of python which really breaks code is 3.0, but there were serious reasons for this evolution of the language. I think python only becomes better with time.

Member Avatar for vegaseat
0
739
Member Avatar for toll_booth

I don't use windows, but I found [this blog entry](http://www.andrewsturges.com/2012/05/installing-numpy-for-python-3-in.html), which is about 1 and a half year old, about possible issues. It may help you.

Member Avatar for vegaseat
0
340
Member Avatar for MSV22

> That is my error because of creating new.py in my working dir. DONT rename the standard library modules ! Also in windows, you can use a small app [locate 32](http://locate32.cogit.net/) to find files named new.py !

Member Avatar for soibac
1
2K
Member Avatar for krystosan

The test fails before the assertRaises is reached, because the FilterList ctor (method `__init__()`) calls `checkListItem()`, which means that you cannot even make a test list with invalid types. As for your approach, it is difficult to answer since we don't know what you want to do with this.

Member Avatar for krystosan
0
365
Member Avatar for Bhavya scripted

One problem is that you start each year with c = 1 on the first day. Since your criterion for [sundays](http://projecteuler.net/problem=19) is `c%6 == 0`. It means that every year starts with a tuesday.

Member Avatar for TrustyTony
1
473
Member Avatar for Ismatus3

Here is an example of creating a hierarchies of folders and files and zipping them in an archive. The main argument is to generate the correct sequence of arguments for `ZipFile.write()`. This is done by post-processing the output of `os.walk()`. #!/usr/bin/env python # -*-coding: utf8-*- import contextlib import itertools import …

Member Avatar for Ismatus3
0
233
Member Avatar for frankenfrank

This can be understood mainly by examining the history of these languages. C++ was an object oriented development of C at the time where OOP was the new paradigm. Perl started as a system scripting language which was more structured than shell languages. It was then heavily used when internet …

Member Avatar for vegaseat
0
425
Member Avatar for james.lu.75491856

Use startpage ! Here is a [related discussion](https://github.com/webpy/webpy/pull/195). You should try and modify net.py according to the last suggestion.

Member Avatar for james.lu.75491856
0
359
Member Avatar for phorce

Here is an example with 2 worker threads. It uses Condition objects to synchronize threads. It is relatively easy to understand if you remember that only one thread may own a given condition at a given time, which means for example that a worker blocks on `with G.wcond` if another …

Member Avatar for Gribouillis
0
11K
Member Avatar for Subhradeep

This is very interesting BearofNH. Unfortunately it does not work with all hardware (eg my laptop :( ). I'm trying to port [this code](https://gist.github.com/jayrambhia/5866483) to python, using the python bindings for v4L2 and opencv2. If it works, I'll make a code snippet. See also [the author's blog](http://jayrambhia.com/blog/capture-v4l2/).

Member Avatar for Gribouillis
0
2K
Member Avatar for krystosan

I would pass json format command '{"India":["New Delhi", "Bangalore"], "Canada": ["Toronto","Vancouver"]}' and in python code import json self.items = json.loads(items) This avoids any eval issue, and eases cross programs calls.

Member Avatar for krystosan
0
283
Member Avatar for RHNation

Because in your code, package_weight is a local variable in function main(). It exists only in this function's body.

Member Avatar for Lardmeister
0
4K
Member Avatar for chanchalrawat

I agree with slate. You want a solution, but you didn't even describe the problem that you want to solve. Invoking the 'consumer producer problem' is far too abstract. Didn't you copy and paste code that you don't understand from the internet ?

Member Avatar for Gribouillis
0
357
Member Avatar for bright.silva

The errors come from bad bookkeeping of the index i def lapping(x1, x2): x1, x2 = str(x1), str(x2) # in case integers are passed to lapping() not_lapped= True #used to test if there was no lapping i = -1 for sets in Big_Set[:-1]: # don't use the last set i …

Member Avatar for bright.silva
0
272
Member Avatar for mike89
Member Avatar for Gribouillis
0
439
Member Avatar for hmx7

> I have no idea what to do. In this case, compute the GPA by hand, without your computer, and write down carefully every detail of your procedure. This should give you the algorithm.

Member Avatar for hmx7
0
790
Member Avatar for ddanbe

Congratulations, this is good python code. Its naming style however is unusual for python code. You may want to read [pep 8](http://www.python.org/dev/peps/pep-0008/), a style guide written for the developpers of the python language trunk. If you follow this style everybody will think you are a very experienced pythonista. Also `string.Template` …

Member Avatar for vegaseat
1
387
Member Avatar for zspoja

In the first version, window is a local variable in function start(). It is probably garbage collected when the function exits. You need to keep a pointer to window.

Member Avatar for zspoja
0
3K
Member Avatar for mohan.jce
Member Avatar for nutrion

What's the output of ping run from a terminal while the script alternates return codes ?

Member Avatar for nutrion
0
199
Member Avatar for Rebecca_2

I would rather count the optimisation achieved lines while reading: import os with open('results.txt', 'a') as writer: for file in os.listdir('.'): if file.endswith('.out'): print(file + ' ', end= ' ', file=writer) opt_cnt = 0 # <-- reset counter for each file with open(file, 'r') as reader: for line in reader.readlines(): …

Member Avatar for snippsat
0
286
Member Avatar for Rebecca_2

`os.walk('.')` means that you are traversing the current working directory with os.walk (as returned by `os.getcwd()`). If you run the code while in the X0.0 directory, os.walk will never see the X0.05 directory. The current working directory does not change during the walk. To create psub in a subfolder, you …

Member Avatar for Gribouillis
0
685
Member Avatar for dabasank
Member Avatar for marethamogale
Member Avatar for Joseph Vann

There are different ways. **1:** declare outline global inside the function outline = True # when the program starts def toggle(*args): # args ignored global outline # at the top of the function if outline == True: outline = False if outline == False: outline = True **2:** use a …

Member Avatar for ZZucker
0
399
Member Avatar for Gribouillis

The syntax of the [icode]str.format()[/icode] method described in [url=http://docs.python.org/library/string.html#formatstrings]the python 2.6 documentation[/url] looks both powerful and complex. The idea of this thread is to start a collection of nice formatting examples which will ease the task of mastering this function. Please post useful examples, and document them :)

Member Avatar for Gribouillis
3
3K
Member Avatar for RHNation

Here are some examples of the `format()` method Python 3.3.1 (default, Apr 17 2013, 22:32:14) [GCC 4.7.3] on linux >>> "Give me {0} and {2}, said the {1} man".format("bacon", "other", "eggs") 'Give me bacon and eggs, said the other man' >>> "Give me {0} and {2} eggs, said the {1} …

Member Avatar for vegaseat
0
8K
Member Avatar for lucpet

It's a very good idea to use parenthesis in your print statements as if you were using a function. It teaches you python 3 at the same time. If you add the line from __future__ import print_function as the first statement of your module, it will turn print into a …

Member Avatar for lucpet
0
215
Member Avatar for RHNation
Member Avatar for giancan

Here is *pseudo code* for each item in list 1: item defines a pair (key, value) eg for the item <14.7992581813 41.5425583232 650.00>, the key is <14.7992581813 41.5425583232> and the value is <650.00>. Store all these pairs (key, value) in a dictionary D, and raise an exception if one of …

Member Avatar for giancan
0
347
Member Avatar for Jacklittle01

Here is an example. The program creates a dictionary containing the current state of the game, using simple data types, then saves this snapshot on disk in a json file: import json if __name__ == "__main__": state = { "player_name" : "bob", "level" : 3, "elapsed_time" : 24.3, "monsters" : …

Member Avatar for james.lu.75491856
0
431
Member Avatar for Rebecca_2

I would start with regular expressions and itertools import itertools import re wanted = ( 'Final energy =', 'Total charge on defect =', 'Final defect energy =', '**** Optimisation achieved ****', ) regex = '^(?:{0})'.format('|'.join(re.escape(s) for s in wanted)) regex = re.compile(regex) with open('filename.txt', 'rb') as lines: lines = itertools.ifilter(regex.match, …

Member Avatar for Gribouillis
0
332
Member Avatar for crag0

I managed to fool the zipfile module by using a StringIO as output file: from StringIO import StringIO class Crazip(StringIO): def __init__(self, capacity): StringIO.__init__(self) self.capacity = capacity self.check() def write(self, data): StringIO.write(self, data) self.check() def writelines(self, lines): for x in lines: self.write(x) def check(self): if self.tell() > self.capacity: raise RuntimeError("Zip …

Member Avatar for Gribouillis
0
364
Member Avatar for vegaseat

For the sake of comparing tools, here is the same code written with the well known [zodb module](https://pypi.python.org/pypi/ZODB) instead of [shelve](http://docs.python.org/3/library/shelve.html#module-shelve). ''' zodb_test.py Use third party module ZODB (zope object database) to create a 'persistent to file' dictionary Python 2 and 3 create files 'phonebook.fs' 'phonebook.fs.index' 'phonebook.fs.lock' 'phonebook.fs.tmp' The files …

Member Avatar for Gribouillis
4
887
Member Avatar for Taruna_1

Apparently, you are using pandas DataFrame instances. The api reference for these objects contains [conversion methods](http://pandas.pydata.org/pandas-docs/dev/api.html#id12). I would try s = df.to_string()

Member Avatar for Taruna_1
0
3K
Member Avatar for Jacklittle01
Member Avatar for Gribouillis
0
248
Member Avatar for farmwife

You should specify python3 only if your code is written in python 3. The bash trick is seldom useful. It is for people too lazy to open an editor to start a python script, or for bash programmers. A more useful idea is to use a file template in your …

Member Avatar for james.lu.75491856
0
244
Member Avatar for farmwife

If not in that directory, you must add it to the $PYTHONPATH variable, not $PATH. ($PATH is for executable programs, not python modules). Another way is to put filename.py in your `site-packages` directory (or your per-user `site-packages` directory). The third way is to dynamically add the folder to `sys.path` at …

Member Avatar for farmwife
0
179
Member Avatar for np complete
Member Avatar for Gribouillis
0
237
Member Avatar for james.lu.75491856
Member Avatar for james.lu.75491856
0
166
Member Avatar for giancan

I suggest that you sort the list on the pair of values and group the records. For example, assuming that the rows are tuples like ("filenameA", 3.14, 5.3, -2.0, 4.0, "notimportant") You can work with import itergadgets @itergadgets.sorter_grouper def by2values(item): return (item[1][1], item[1][2]) def extract_rows(sequence): """extract the desired rows from …

Member Avatar for Gribouillis
0
235
Member Avatar for james.lu.75491856
Member Avatar for Reethu_1

Assuming that all the lists are circular (see the title), it can be done without a set. The idea is that the lists are very easy to reverse because they are built in the reversed order. In the code below, I write a function to reverse a circular list, then …

Member Avatar for TrustyTony
0
811
Member Avatar for sujan.dasmahapa
Member Avatar for almostbob
0
4K
Member Avatar for 3e0jUn

Use an existing parser generator module. There are tenth of them in python.A very interesting one, and easy to use is [parcon](https://pypi.python.org/pypi/parcon). See also [the parcon blog](http://blog.parcon.opengroove.org/).

Member Avatar for 3e0jUn
0
141
Member Avatar for james.lu.75491856

> I still need to set a global variable because It carrys over function calls Use a single global object class _MuCacheData(object): def __init__(self): # define here arbitrary containers that you need pass def mu_cache(self, func, maxsize = 128): # write and return your wrapper here # Access persistent data …

Member Avatar for sepp2k
0
349
Member Avatar for Jake_1

The End.