2,646 Posted Topics
Re: It is probably `/usr/bin/env` . Try `which env` in a terminal. | |
Re: Startpage led to [this blog entry](https://medium.com/p/f2fa442daf99). Perhaps you have lxml on one OS and not on the other. | |
Re: Did you check that the coverage module is installed ? $ pydoc coverage In linux mint, coverage is available via the package `python-coverage` . | |
Re: 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. | |
Re: 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. | |
Re: > 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 ! | |
Re: 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. | |
Re: 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. | |
Re: 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 … | |
Re: 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 … | |
Re: 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. | |
Re: 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 … | |
![]() | Re: 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/). |
Re: 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. | |
Re: Because in your code, package_weight is a local variable in function main(). It exists only in this function's body. | |
Re: 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 ? | |
Re: 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 … | |
Re: May I suggest virtualbox + linux ? (just installed rpy2 in one click in linux mint kde) | |
Re: > 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. | |
Re: 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` … | |
Re: 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. | |
Re: Dos' *tasklist* command seems to support connecting to a remote system. | |
Re: What's the output of ping run from a terminal while the script alternates return codes ? | |
![]() | Re: 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(): … |
![]() | Re: `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 … |
Re: Have look at the `os.walk()` function. | |
Re: Where are your efforts to solve the assignment ? | |
Re: 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 … | |
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 :) | |
Re: 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} … | |
Re: 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 … | |
Re: galons_used and gallons_used are 2 different variables. Typo. | |
Re: 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 … | |
Re: 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" : … | |
![]() | Re: 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, … |
Re: 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 … | |
Re: 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 … | |
Re: 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() | |
Re: Python has Lettuce. But cucumber claims to work with python too. | |
Re: 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 … | |
Re: 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 … | |
Re: Can you give a generic example of such a string and the expected result ? | |
| |
Re: 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 … | |
Re: What is your question ? | |
Re: 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 … | |
Re: Try `Example\$319`. Your shell interpretes the $ sign in command lines before executing them. | |
Re: 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/). | |
Re: > 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 … | |
Re: These [books](http://inventwithpython.com/index.html) may help you. |
The End.