2,646 Posted Topics

Member Avatar for kouty

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, …

Member Avatar for Gribouillis
0
409
Member Avatar for Gribouillis

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 …

Member Avatar for Gribouillis
4
524
Member Avatar for sneekula

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 ?

Member Avatar for TrustyTony
1
14K
Member Avatar for shafter111

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 …

Member Avatar for sneekula
0
31K
Member Avatar for Shaji_1

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)

Member Avatar for TrustyTony
0
307
Member Avatar for sneekula

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 …

Member Avatar for RobertHDD
0
166
Member Avatar for Niloofar24

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. …

Member Avatar for Niloofar24
0
1K
Member Avatar for kouty

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

Member Avatar for kouty
0
189
Member Avatar for faizlo

You can do it in a one-liner total = sum(float(x) for x in '1.32, 5.32, 4.4, 3.78'.split(','))

Member Avatar for Gribouillis
0
277
Member Avatar for sneekula

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

Member Avatar for vegaseat
0
394
Member Avatar for clife

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.

Member Avatar for Gribouillis
0
240
Member Avatar for Slavi

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).

Member Avatar for Ene Uran
0
265
Member Avatar for Slavi

Did you try pypi packages such as https://github.com/Infinidat/infi.registry or https://pypi.python.org/pypi/registry/0.4.2 ?

Member Avatar for Ene Uran
0
182
Member Avatar for steven.rose.94

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 ?

Member Avatar for steven.rose.94
0
359
Member Avatar for diafol
Member Avatar for Slavi
Member Avatar for Lardmeister
1
209
Member Avatar for sweetsmile

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.

Member Avatar for sweetsmile
0
479
Member Avatar for EdJones

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() …

Member Avatar for vegaseat
0
6K
Member Avatar for IneedHELP2020

The best thing to do is to post your program here and explain what doesn't work.

Member Avatar for vegaseat
0
113
Member Avatar for Gribouillis

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 …

Member Avatar for Gribouillis
0
446
Member Avatar for Nancy 92
Member Avatar for Slavi
Member Avatar for HiHe

You can try something along the line of ss = re.sub(r'^\d+ ?', '', s, re.MULTILINE)

Member Avatar for vegaseat
0
1K
Member Avatar for fahadkalis

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.

Member Avatar for fahadkalis
0
245
Member Avatar for Chem_1
Re: IDE

I discovered the [enki](http://enki-editor.org/) editor today. It seems worth giving a try !

Member Avatar for sneekula
0
679
Member Avatar for PCSAWICK829

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]`.

Member Avatar for sneekula
0
2K
Member Avatar for mark103

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))

Member Avatar for Gribouillis
0
427
Member Avatar for vegaseat

@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 …

Member Avatar for Gribouillis
1
436
Member Avatar for tony75

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 …

Member Avatar for tony75
0
2K
Member Avatar for RikTelner

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!

Member Avatar for RikTelner
0
134
Member Avatar for mark103

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.

Member Avatar for mark103
0
658
Member Avatar for fonzali

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. …

Member Avatar for Gribouillis
2
233
Member Avatar for noronet

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.

Member Avatar for Gribouillis
0
89
Member Avatar for varshaholla

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.

Member Avatar for Gribouillis
0
345
Member Avatar for MasterChat
Member Avatar for vegaseat
0
258
Member Avatar for EdJones

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) …

Member Avatar for EdJones
0
158
Member Avatar for stan3688

Add a print statement to start a new line for score1 in list1: for i in range(0,score1): print "*", print

Member Avatar for Gribouillis
0
239
Member Avatar for mark103
Member Avatar for Chrislynn_1

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 …

Member Avatar for Chrislynn_1
0
239
Member Avatar for ~s.o.s~
Member Avatar for Borzoi
Member Avatar for JasonHippy
0
1K
Member Avatar for tony75

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...

Member Avatar for Gribouillis
0
7K
Member Avatar for Slavi

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 …

Member Avatar for vegaseat
0
240
Member Avatar for wesam.teto.9

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, …

Member Avatar for Gribouillis
0
229
Member Avatar for EdJones

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 …

Member Avatar for Gribouillis
0
134
Member Avatar for vegaseat

[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 …

Member Avatar for Gribouillis
0
20K
Member Avatar for Slavi

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, …

Member Avatar for Slavi
0
507
Member Avatar for Gribouillis

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 …

Member Avatar for Gribouillis
1
1K
Member Avatar for Slavi

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/).

Member Avatar for Slavi
0
2K
Member Avatar for Cort3z

[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 …

Member Avatar for Puneet_1
0
16K

The End.