2,646 Posted Topics
Re: Ok, so here is a new standard lib candidate import re def overcount(S, sub, start=0, end=None): """overcount(S, sub[, start[, end]]) -> int Return the number of overlapping occurences of substring sub in string S[start:end]. """ p = r'(?={})'.format(re.escape(sub)) t = () if end is None else (end,) return len(re.compile(p).findall(S, start, … | |
I uploaded a module named [symboldict](https://pypi.python.org/pypi/symboldict) to the python package index (pypi). This snippet shows how to use it to create a dictionary of symbols from various modules. This dictionary can be used as a common language shared by several modules. It can be used to load python libraries in … | |
Re: It is interesting although I cannot make it work in linux with KDE. However, a search for `clipboard` in pypi yields a number of results. Among them, [pyperclip](https://pypi.python.org/pypi/pyperclip/) looks promising. Which is the best module for clipboard access ? | |
Re: There was a PEP about this, https://www.python.org/dev/peps/pep-0315/ . It was discussed and rejected by Guido Van Rossum who gave the reason: >Please reject the PEP. More variations along these lines won't make the language more elegant or easier to learn. They'd just save a few hasty folks some typing while making … | |
Re: There is also a solution with the re module import re def cap(match): return match.group(0).capitalize() with open('c:\FLOUpper.txt', 'r') as infile, open('c:\FLOLower.txt', 'w') as outfile: s = infile.read() s = re.sub(r'\b[a-zA-Z]\w*', cap, s) outfile.write(s) | |
Re: You can also burn a DVD with the appropriate version of kubuntu. Go here http://www.kubuntu.org/getkubuntu and choose Kubuntu 14.04 (long term support). If your PC is 64 bits choose the 64 bits version. Make sure the computer is connected to your modem by a cable, Then reboot the computer on this … | |
Re: Can you post your script? It depends on what you want to do. For example, here is a function which prints hello world #!/usr/bin/env python # -*-coding: utf8-*- # This is file hello.py # Line 1 above tells the linux shell that this # program must be executed with python. … | |
Re: The else part must go with the for. It is only executed if the for loop was not interrupted by a break statement for i in range (2, 25): if 25 % i == 0: break else: print (25, " is a prime number.") See the doc https://docs.python.org/3/reference/compound_stmts.html#the-for-statement | |
Re: You can do it in a one-liner total = sum(float(x) for x in '1.32, 5.32, 4.4, 3.78'.split(',')) | |
Re: On my system it is sudo apt-get install python-matplotlib python3-matplotlib python-pil python3-pil It is easier to find packages with aptitude sudo apt-get install aptitude aptitude search pil | |
Re: If you don't mind using a third party library, you may consider [psutil](https://code.google.com/p/psutil/wiki/Documentation#Classes) where process objects have `get_nice()` and `set_nice()` methods. | |
Re: If the dictionary file was created on windows, it may have windows-like end of lines. Try to open the dictionary file with mode 'rU' (universal newlines). | |
Re: Did you try pypi packages such as https://github.com/Infinidat/infi.registry or https://pypi.python.org/pypi/registry/0.4.2 ? | |
Re: We see the failing regex, but we don't know how it fails. Can you post a fully failing python example with a (short) concrete respData ? | |
![]() | |
Re: You can give your neighbor an electronic cigarette. Many heavy smokers (including me) stopped with the e-cigarette. Give him e-liquid with 11mg nicotine to start with. | |
Re: This is perhaps a more efficient way to generate the same kind of random image >>> from PIL import Image >>> import os >>> size = (600, 600) >>> im = Image.new('RGB', size) >>> def ran(): ... return os.urandom(600*600) ... >>> pixels = zip(ran(), ran(), ran()) >>> im.putdata(list(pixels)) >>> im.show() … | |
Re: The best thing to do is to post your program here and explain what doesn't work. | |
Sometimes you want the value of a variable to be related to its name in the source code. For example, the variable x should have the value "var x". This is especially useful when you perform symbolic computations with python (with the sympy module for example). In standard python, the … | |
| |
Re: You can try something along the line of ss = re.sub(r'^\d+ ?', '', s, re.MULTILINE) | |
Re: An extremely simple way to send data from one computer to another is to use an xml_rpc server. Try to run the example code in the python documentation for the xml-rpc protocol. An example server on one machine, the example client on the other machine. | |
Re: I discovered the [enki](http://enki-editor.org/) editor today. It seems worth giving a try ! | |
Re: You must indent line 50 to 89 (they belong to the while loop) and you must probably change `raspberry[1]` at line 79 with `raspberryPosition[1]`. | |
Re: What is your database ? You are trying to perform multiple SQL statements at the same time. In the usual python dbapi, this is done with [cursor.executemany()](https://www.python.org/dev/peps/pep-0249/#executemany). Did you try cur.executemany("INSERT INTO buttons(button_ids, button_width)" + " VALUES(?, ?)", zip(program_id, program_width)) | |
Re: @slavi Using a password manager, you can easily have unique random uncrackable passwords with more than 20 characters. The only password you need to remember is the password manager's password. I don't know any of my passwords but one or two, and I have many accounts, each with an impossible … | |
Re: In python, one can execute a program using the subprocess module. For example, you can use [this snippet](https://www.daniweb.com/software-development/python/code/257449/a-command-class-to-run-shell-commands-) to get program output, error messages and exit status. With this, you can easily build a program `third.py` which executes the two initial binaries. Then you could use py2exe to get a … | |
Re: It could be useful in combination with raspberry pi computers which have no input and output devices. Well. We're waiting for your online store! | |
Re: There may be indention issues in your code. What is the `self` at lines 28 and 36 for example? Also avoid to have two different variables `program_buttons` and `programs_button` in the same file. | |
Re: Merry Christmas! The look is very similar to [DrPython's](http://drpython.sourceforge.net/screenshots.html), which was also designed for teaching purposes (I think it was a python version of a DrScheme (now DrRacket) related to *how to think like a computer scientist*). He could perhaps start with DrPython's GUI. Edit: hm, DrPython is in wxpython. … | |
Re: I think you need the ability to run a program on the remote computer. This can be achieved with a ssh server on the remote computer. | |
Re: Where did you get that code ? Your input file is not a csv file. You'll have to write your own parser for the text file. Perhaps the starting point could be to write your desired xml output by hand. You must first determine where you want to go. | |
Re: Marrakech, in october. It was like summer with 35°C (95°F). | |
Re: You are *wrapping* the `str` class. It means that you want a string, but you don't want the string methods (such as addition or `index()`, etc). Instead, you want your own methods. Did you consider subclassing `str` like this class Sentence(str): __slots__ = () def __new__(cls, *args): s = ''.join(str(a) … | |
Re: Add a print statement to start a new line for score1 in list1: for i in range(0,score1): print "*", print | |
Re: Perhaps you mean if position_x == 375: print position_x ? | |
Re: A configuration file is usually a reasonably sized file, and you can load its content in memory as a python string or a python list of lines. You could cut this string and insert your new content as in this example: >>> s = "foo a e ueiue uie uie … | |
Re: A long time ago, I used Jed in a terminal. It is a nice text editor. | |
Re: I never tried this, but the `iat` tool is a converter to iso9660 (see [here](http://2buntu.com/articles/1436/mounting-bin-and-iso-files-in-linux/) for example), then [here](http://askubuntu.com/questions/388037/how-to-create-an-ubuntu-img-file-from-iso-on-ubuntu) is a discussion about iso and img... | |
Re: The line #!/usr/bin/python -tt is not a python thing. It is a unix mechanism named [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)). If the file is made executable in unix, the first line of the file is parsed and if it contains the shebang structure, the OS knows that it must execute the program on the … | |
Re: Well, it could be something like def Similarity(X,Y): for i in range(m+1): SIM[i,0] = ig for j in range(1, n+1): SIM[0,j] = jg for i in range(1, m+1): for j in range(1, n+1): SIM[i,j] = max( SIM[i-1,j-1] + s(X[i],Y[j]), SIM[i-1,j]+g, SIM[i,j-1]+g ) return SIM[m,n] but we don't know what `X, … | |
Re: Here is a version using generators. #!/usr/bin/env python3 """This script simulates a monkey on a typewriter trying to come up with one sentence of Shakespeare. Only the lowercase alpha characters are used and the sentence is "methinks it is like a weasel" """ import random import string TEST_STRING = "methinks … | |
Re: [QUOTE=CS guy;1618262]@vegaseat: You are very wrong. Well, I haven't timed it, but theoretically it should be. Because, with multiple separate replaces you're running through the whole text string for every key in the dictionary, whereas the OP's regex method traverses 'text' just once. For short texts this may not make … | |
Re: I started with slackware about 20 years ago, then Red Hat, then Mandriva, until it died, but today, my favorite distro is Kubuntu because it works flawlessly. Kubuntu 14.04 LTS is supported untill 2019, and I'm expecting 5 peaceful years as a linux user with KDE, no ads, no bugs, … | |
Importing a hierarchy of firefox bookmarks in konqueror can be tricky, as konqueror's bookmarks editor doesn't read firefox's sqlite databases where the bookmarks are stored. Konqueror bookmarks are normally stored in a file `~/.kde/share/apps/konqueror/bookmarks.xml` , which is actually a dialect of `xml` named `xbel`. I found very little documentation about … | |
Re: If I were you, I would try the boot-repair disk. It always repaired my broken boots in one click. Unfortunately, sourceforge is currently down, and I'm not sure you can download the disk. Edit: if you have a live ubuntu disk, you can run boot-repair as explained [here](http://www.howtogeek.com/114884/how-to-repair-grub2-when-ubuntu-wont-boot/). | |
Re: [QUOTE=Cort3z;1398912]If you have read my initial post it sais "the code works just fine...". The problem is siply that there are _extra_ spaces that appear when I run the multi threade version. It seems as though one of the threads, for no apparent reason, decides to add a space in … |
The End.