2,646 Posted Topics

Member Avatar for DougArndt

I think it works well. I changed the code to clip with [`np.clip()`](http://docs.scipy.org/doc/numpy/reference/generated/numpy.clip.html) and plot the wave with [matplotlib](http://matplotlib.org/) in [ipython notebook](http://ipython.org/notebook.html) (This was done with python 2). See the plot below y_wavearray = np.array(wave,np.float64) y_clipped = np.clip(y_wavearray, -np.inf, 15000) x_points = len(wave) +1 x_values = np.arange(1,x_points) x_array = np.array(x_values,np.float64) …

Member Avatar for Gribouillis
0
768
Member Avatar for ajit.nayak

You could try and install pyparsing with the [windows installers](https://pypi.python.org/pypi/pyparsing/2.0.1) in pypi.

Member Avatar for Gribouillis
0
697
Member Avatar for dean.ong.14
Member Avatar for aVar++

> There is a moment is every woman's life, when she wants to do something forbidden. Easy, the opposite is: *Some women never want to do anything forbidden*. Another solution was if int(menu) not in (1, 2):

Member Avatar for Gribouillis
0
249
Member Avatar for tunisia
Member Avatar for Jade87

In linux, the [`file` command](https://en.wikipedia.org/wiki/File_%28command%29) can help you too.

Member Avatar for Jade87
0
375
Member Avatar for rbyrd

I suggest change your password for `foobarbazqux`, then uninstall wxpython, then change your password again.

Member Avatar for Gribouillis
0
79
Member Avatar for Jamblaster

I disapprove inflammatory debates in daniweb. I had one once with a knowledgeable programmer and some time later, he ceased to connect. I think he had too strong convictions and he wanted everybody to agree.

Member Avatar for diafol
1
376
Member Avatar for Craig_2

Very good. I would have written `shutil.move(files, client_folder)`. Another solution is to create a sequence of files to move first def to_move(folder): """generate the files to move""" wd = os.getcwd() os.chdir(folder) try: for name in glob.glob('*.*'): if 'client_name' in str(name).lower(): yield os.path.join(folder, name) finally: os.chdir(wd) src_dir = r'd:\Desktop' L = …

Member Avatar for Craig_2
0
409
Member Avatar for ZielonySBS

[QUOTE=longr59;1118842][CODE] #!/usr/bin/python import sys, os, time, shutil print time.ctime() path = "/home/richard/test/" files = os.listdir(path) files.sort() for f in files: src = path+f dst = "/home/richard/Desktop/test/" +f shutil.move(src, dst) print time.ctime() [/CODE][/QUOTE] Using functions from [url=http://www.daniweb.com/code/snippet239496.html]this code snippet[/url] and [url=http://www.daniweb.com/code/snippet254626.html]this code snippet[/url], you can also write [code=python] with WorkingDirectory("/home/richard"): tgz …

Member Avatar for Gribouillis
0
19K
Member Avatar for CodingCabbage

Don't use `sleep()` in gui programs. Use a timer instead (method `after()` in tkinter). Run [this example](http://www.daniweb.com/software-development/python/code/384025/color-changing-window-demo-of-tkinter-after-timer-events) by PyTony to see how it works.

Member Avatar for CodingCabbage
1
14K
Member Avatar for CodingCucumber

If there is an open window, it means that the program is still running. Your question is a contradiction. What you can do is launch the turtle program from another program which exits immediately. For example here is a turtle program # progA.py from turtle import * angle = 5 …

Member Avatar for Gribouillis
0
304
Member Avatar for Lost&Found
Member Avatar for Gribouillis
0
309
Member Avatar for dean.ong.14

Try self.btnquit = button(calc_frame, "Quit", tk.destroy) self.btnquit.pack(side = LEFT) in method init, before `self.input = ...`.

Member Avatar for dean.ong.14
0
198
Member Avatar for Jamie_2

You can shorten the tests from graphics import * def patchdrawer(): win = GraphWin("Patch drawer", 100, 100) for x in range(0, 5): for y in range(1, 6): p1 = Point(x * 20, (y - 1) * 20) p2 = Point((x + 1) * 20, y * 20) rectangle = Rectangle(p1, …

Member Avatar for Jamie_2
0
654
Member Avatar for evaldas.blauzdziunas

Check that **every** line in `msgs.txt` consists of 3 items separated by `#`.

Member Avatar for evaldas.blauzdziunas
0
351
Member Avatar for manohar1111

Here is an example of redirecting command `'python -V'` to a file with the subprocess module import subprocess with open('foo.out', 'wb') as ofh: process = subprocess.Popen(['python', '-V'], stdout = ofh, stderr = ofh) with open('foo.out', 'rb') as ifh: print(ifh.read())

Member Avatar for Gribouillis
0
189
Member Avatar for lewashby

I get something in my linux system with module pyudev >>> from pyudev import Context, Device >>> context = Context() >>> d = Device.from_device_file(context, '/dev/sda') >>> d.subsystem u'block'

Member Avatar for woooee
0
540
Member Avatar for Gribouillis

This snippet prints a python list of strings in multicolumn format (similarly to linux `ls` command). It uses module prettytable, available in [pypi](https://pypi.python.org/pypi/PrettyTable).

Member Avatar for Gribouillis
3
2K
Member Avatar for chophouse

Useful tips: import funky print(funky) print(funky.__file__) This prints the path to the file where the module was found. Very useful when a module behaves in an strange way.

Member Avatar for chophouse
0
17K
Member Avatar for venkaaaaat

You can use the Command class in [this code snippet](http://www.daniweb.com/software-development/python/code/257449/a-command-class-to-run-shell-commands). You would write com = Command("./vershion.sh").run() if com.failed: print(com.error) else: print(com.output)

Member Avatar for manohar1111
0
593
Member Avatar for Gribouillis

This snippet is reserved for users of the KDE linux desktop. It adds a *service menu* to kde applications such as dolphin and konqueror, to launch an ipython dashboard in a directory in one click. More specifically, save the text of this snippet as a file `~/.kde/share/kde4/services/ServiceMenus/opennotebook.desktop` (create the directory …

1
632
Member Avatar for CodingCabbage

Partial does [currying](https://en.wikipedia.org/wiki/Currying): >>> from functools import partial >>> >>> def FOO(x, y, z): ... print((x, y, z)) ... >>> BAR = partial(FOO, "baz", "qux") >>> BAR(3.14) ('baz', 'qux', 3.14) BAR is the same function as FOO, but it takes only one argument (the last argument). The 2 first arguments have …

Member Avatar for vegaseat
0
243
Member Avatar for CodingCabbage

Every gui problem has already been solved by vegaseat. Type `tkinter bargraph` in daniweb's search form and you'll find many examples, like [this one](http://www.daniweb.com/software-development/python/code/216816/draw-a-bar-graph-python), still fully working after 7 years !

Member Avatar for vegaseat
0
285
Member Avatar for Prithiv_1

Perhaps convert to dict first def main(args): f = open(args[1], 'w') inp = raw_input("Enter a Dict") # inp = {"a":1,"b":2} inp = django.utils.simplejson.loads(inp) assert isinstance(inp, dict) django.utils.simplejson.dumps(inp, f)

Member Avatar for vegaseat
0
292
Member Avatar for Netcode

The 4 letters words are nodes in a graph where adjacent nodes differ by one letter from the current node. Starting from the startword, you can do a depth first walk of the graph until you reach the endword. I posted a clue for depth first traversal [here](http://www.daniweb.com/software-development/python/threads/466930/adding-limit-to-web-crawler#post2033672) (replace urls …

Member Avatar for Netcode
0
296
Member Avatar for chophouse

The obvious error is that the file argument in storbinary() must be an open file object instead of a string. Try with open(sourcepath, 'rb') as ifh: ftps.storbinary(outbound, ifh, 8192)

Member Avatar for chophouse
0
9K
Member Avatar for Stefano Mtangoo

BeautifulSoup 4.1.3 is out since August 20, 2012. It is compatible with python 2.6+ and python 3 !

Member Avatar for vegaseat
0
985
Member Avatar for XodoX

It works for me and python 2.7. The output is A: array([[ 7, 3, -1, 2], [ 3, 8, 1, -4], [-1, 1, 4, -1], [ 2, -4, -1, 6]]) P: array([[ 1., 0., 0., 0.], [ 0., 1., 0., 0.], [ 0., 0., 1., 0.], [ 0., 0., 0., …

Member Avatar for Gribouillis
0
2K
Member Avatar for krystosan

At first glance, the error means that the symmetric difference is empty and your code does not handle the case.

Member Avatar for krystosan
0
1K
Member Avatar for Jacklittle01

Your question is very opaque. I suspect it is already encrypted. Nevertheless, try this: try: input = raw_input except NameError: pass data = input("Please enter a 64 letters string: ") if len(data) == 64: print("SUCCESS") else: print("FAILURE")

Member Avatar for vegaseat
0
175
Member Avatar for CodingCabbage

Your favorite search engine can help you with SQL syntax. Here is [an answer](http://www.tutorialspoint.com/sqlite/sqlite_using_autoincrement.htm) to your question.

Member Avatar for vegaseat
0
614
Member Avatar for laura301019

You must do a depth first traversal for this. The algorithm is very simple: suppose the urls line up at the post office with a number D written on their T-shirt, representing their depth. For every url, a web page is loaded and new urls discovered. The urls which have …

Member Avatar for Gribouillis
0
450
Member Avatar for antonio.neal.39

**Not working** --> Exception thrown. Solve the issue described by the exception traceback ! Look [here](http://docs.python.org/3/library/urllib.request.html#module-urllib.request).

Member Avatar for HiHe
0
222
Member Avatar for CodingCabbage

It is not exactly the scheme. In python there is a [DB-API](http://www.python.org/dev/peps/pep-0249/), which many database modules, like sqlite3, try to implement. What this api says in short, si that the pseudo code looks like create a Connection object (using the db file name) create a Cursor object for this connection …

Member Avatar for Gribouillis
0
359
Member Avatar for rajeeeesh
Member Avatar for vegaseat
0
147
Member Avatar for tinku.cater

There are many things to change in your code. Solve the issues one by one with the help of the exception tracebacks printed by python. Here tre traceback is Traceback (most recent call last): File "./payrate.py", line 42, in <module> main() File "./payrate.py", line 7, in main payrate,hours=totalhours TypeError: 'float' …

Member Avatar for Gribouillis
0
280
Member Avatar for a8med

It is a very good idea to use a class instance to handle this. You can add a parameter `self` to all the functions and refactor the code like this: import random # ... think = ("Tänk på ett fyrsiffrigt tal med olika siffror") class Mastermind: def __init__(self): self.nya_gissningen = …

Member Avatar for vegaseat
0
232
Member Avatar for cdwin

Here is a math 'black box' that you can use from nzmath.gcd import extgcd from nzmath.matrix import Matrix def decrypt_key(cyph, uncyph, nletter): A = Matrix(2, 2, list(cyph)) D = A.determinant() u, v, d = extgcd(D, nletter) if d != 1: raise RuntimeError("Can not compute key matrix") B = (Matrix(2, 2, …

Member Avatar for vegaseat
0
2K
Member Avatar for ptim123

Sending your code to the python interpreter yields File "<ipython-input-1-18413f1ea40a>", line 3 w=[l[0],l[1],l[2],l[3],l[4]) ^ SyntaxError: invalid syntax Please correct the syntax first and post code that python accepts to run.

Member Avatar for Gribouillis
-1
163
Member Avatar for krystosan

When fromlist is empty, `__import__('A.B.C')` returns module A, although it loads A, A.B and A.B.C and inserts them in sys.modules. Try mod = __import__("A.B.C", fromlist=["__name__"])

Member Avatar for Gribouillis
0
210
Member Avatar for Alexander_2

Improve woooee's idea by raising an exception class HangmanError(Exception): pass # ... fname="/path/to/file/images/0.gif" if os.path.isfile(fname): level=PhotoImage(file=fname) else: raise HangmanError(("No such file:", fname))

Member Avatar for vegaseat
0
8K
Member Avatar for krystosan

I suggest import pkgutil import os import sys L = list(sys.builtin_module_names) L += list(t[1] for t in pkgutil.iter_modules()) L = sorted(L) dst = os.path.expanduser("~/Desktop/modules.txt") with open(dst, "w") as ofh: ofh.write('\n'.join(L))

Member Avatar for krystosan
0
204
Member Avatar for jantrancero

You can try hr, sc = divmod(counter, 3600) mn, sc = divmod(sc, 60) msg = '%d hours, %d minutes and %d seconds' % (hr, mn, sc) print(msg)

Member Avatar for CaptainFApin
0
2K
Member Avatar for ChicagoBears2012_1
Member Avatar for pygeek

I could not reproduce the bug on my system. Considering that you read the file with mode 'rb', perhaps you should write it in mode 'wb'.

Member Avatar for pygeek
0
482
Member Avatar for sreetha

This forum is not an online homework service. We can help with issues in **your** implementation of the problem. Show some effort and post your attempts to find the bigrams.

Member Avatar for Gribouillis
0
114
Member Avatar for talat.zaitoun

In a sequence `if...elif...elif...elif`, only the first *true* alternative is executed. Use a print to see what happens: def my_startswith(s1, s2): print((s1[0] == s2[0], s1[0] != s2[0], s2 == '', s1 == '' and s2 == '')) if s1[0] == s2[0]: return True elif s1[0] != s2[0]: return False elif …

Member Avatar for Gribouillis
0
225
Member Avatar for krystosan
Member Avatar for Gribouillis

You can teach your linux system that executable python files must be executed with /usr/bin/python. This allows you to write python scripts without the shebang line [icode]#!/usr/bin/env python[/icode]. This snippet shows you how to do it !

Member Avatar for Gribouillis
0
1K

The End.