3,386 Posted Topics

Member Avatar for chophouse

Do shallow copy of input list as list is mutable by slice [:] or .copy() method call.

Member Avatar for chophouse
0
298
Member Avatar for lionaneesh
Member Avatar for vegaseat
0
668
Member Avatar for Gribouillis

Looks like the doctest can not handle def statements from log of IDLE command prompt. [CODE]C:\py>script_from_examples.py ex2.txt def sum(a,b): # Expected: ## return a+b C:\py>type ex2.txt >>> def sum(a,b): return a+b [/CODE] Plain CMD Python prompt shows it differently: [CODE]>>> def sum(a,b): ... return a+b ...[/CODE]

Member Avatar for Gribouillis
3
907
Member Avatar for Curious Gorge
Member Avatar for Bradoz
Member Avatar for Chrome 142

tuples of function calls without using their return values here are very strange for me def openFiles(selection): if selection == "animation": saveAnim(), animation() if selection == "compositing": saveComp(), compositing() return

Member Avatar for Chrome 142
-1
406
Member Avatar for b6huss

Most natural way is list comprehesion. http://www.pythonforbeginners.com/lists/list-comprehensions-in-python/

Member Avatar for snippsat
0
403
Member Avatar for jess.lovejoy.7

Maybe you should try specialist forums or Stack Overflow to find expert on the subject: http://r-dir.com/community/forums.html

Member Avatar for TrustyTony
0
225
Member Avatar for awahqn

Maybe you should simply recode the app? Here my example gmail sending snippet in Python: http://www.daniweb.com/software-development/python/code/380881/python-3-and-python-2-send-email-through-gmail

Member Avatar for TrustyTony
0
215
Member Avatar for kxjakkk

We do not understand as the tree has single cargo contents, nothing about expressions. You must include example data also, output you get for that and the desired result.

Member Avatar for kxjakkk
0
475
Member Avatar for henry.moore.319247

Here is your print function transformed to conform common style rules of PEP8 from __future__ import print_function class Customers(object): def __init__(self, sur_name = None, first_name = None, address = None, town = None, post_code = None, phone_number = None, date = None, email = None): self.sur_name = sur_name self.first_name = …

Member Avatar for TrustyTony
0
316
Member Avatar for sandhya1202

Consider if you are dealing with single word or set of words belonging in classes. Also think is it better to go through the words in file and find where they belong or look for words that belong to some class for each class? I think you must loop over …

Member Avatar for Vikram Kolla
0
343
Member Avatar for zina_a
Member Avatar for krystosan

There seems to be already many discussions about this in net, by quick Google, maybe this could help you: http://stackoverflow.com/questions/2564137/python-how-to-terminate-a-thread-when-main-program-ends

Member Avatar for TrustyTony
0
2K
Member Avatar for loulou.skr
Member Avatar for ~s.o.s~
0
216
Member Avatar for sys73r
Member Avatar for David W
0
424
Member Avatar for lewashby

`artist_string.upper() or artist_string.lower() not in line` Should be as per Gribouillis explanation `artist_string.upper() not in line and artist_string.lower() not in line` And so on. But probably it should be so that you make: `artist_string.lower() not in line.lower()`

Member Avatar for TrustyTony
0
398
Member Avatar for abaddon2031

Why you are using StringIO here? Just build the string normally and send it. Python pseudo-code: send_mail(address, subject,'\n'.join(info_i_want(big_file) for big_file in list_of_files if size_of(big_file) > SIZE_LIMIT)

Member Avatar for TrustyTony
0
281
Member Avatar for Jolie Tia

Line six is opening the file sample.txt as many times as there is files in dir without saving it for later use. I think that is not what you are after. The error simply says that such file as does not exist, but it is strange that it is missing …

Member Avatar for Jolie Tia
0
389
Member Avatar for keegansch

You are changing input function to mean input values hiding the original meaning. Your approach should work even if it is not ideal. Using index position loops is also ugly and it is better to iterate over items in for loop. Things get much clearer once you learn about functions …

Member Avatar for David W
0
369
Member Avatar for tubs1
Member Avatar for Gribouillis
0
570
Member Avatar for abaddon2031
Re: Def

Unfortunately I do not understand your algorithm. I have one snippet I have posted connected with file tree walking, if you like to check it: http://www.daniweb.com/software-development/python/code/316585/scan-filetree-for-files-containing-text

Member Avatar for abaddon2031
0
225
Member Avatar for ddanbe

The writing style is clear and crisp, but I would prefer turtle graphics code to be more sparing of gotos, even they are not program gotos. Usually you do routine so that is relative to turtle direction and maybe returns to starting position. Then you could just loop colors, turn …

Member Avatar for ddanbe
3
2K
Member Avatar for TrustyTony

Here some old fashioned line input routine, better idea nowadays would be to use GUI input box with real editing. Anyway, it is quite simple with Python to do this basic routine for terminal based program.

Member Avatar for fonzali
4
514
Member Avatar for lewashby

Do you mean that you can not explicitly change to string like: #!/usr/bin/env python3 import sys file = sys.argv[1] f = open(file, 'rb') f.seek(-125, 2) artist = f.read(30) newartist = str(artist, 'UTF8').rstrip('\x00') print(new) f.close()

Member Avatar for lewashby
0
4K
Member Avatar for dany12

I wrote one code snippet on line input with reenter possibility today. http://www.daniweb.com/software-development/python/code/479987/simple-line-input-with-reentering-possibility-unlimited-lines

Member Avatar for TrustyTony
0
323
Member Avatar for Tcll

Gribouillis surely can come out with something, ask more specifically. Here his earlier post containing importing ast, response to my code snippet: http://www.daniweb.com/software-development/python/code/389822/averaging-iterable-without-making-copy-of-values#post1680277

Member Avatar for Tcll
0
606
Member Avatar for mustafa.bahaa

Have you read this tutorial article? http://www.daniweb.com/software-development/c/tutorials/45806/user-input-strings-and-numbers-c

Member Avatar for Ayrton C.
0
421
Member Avatar for lewashby

\x00 is byte, not 4, you can strip those with `.rstrip('\x00')` >>> b'Rooster\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' 'Rooster\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' >>> _.rstrip('\x00') 'Rooster' >>>

Member Avatar for lewashby
0
339
Member Avatar for pramitkumarpal

You have list with value for while condition, which is never empty, so this while never terminates in case of not found. Remove [] No need to shout with CAPITALIZEd words.

Member Avatar for TrustyTony
0
296
Member Avatar for ChadSauce
Member Avatar for silverdust
Member Avatar for bob_8

I can not understand what you are after, this does not sound like problem of finding the correct algorithm for problem, it sounds more like you already have the pseudo code algorithm given to you.

Member Avatar for nouth
0
823
Member Avatar for Tamara_1

Maybe I am bit dense, but I do not know what you are after. Here is my own quadratic solver in code snippets: http://www.daniweb.com/software-development/python/code/356952/pep8-quadratic-equations-solver

Member Avatar for ddanbe
1
540
Member Avatar for afnan Qureshi

Sorry, we are not psychic, could you post relevant piece of your code and clear question (with error messages included)

Member Avatar for TrustyTony
0
138
Member Avatar for TrustyTony

I did code for challenge that I saw posted for C# by deceptikon: http://www.daniweb.com/software-development/csharp/threads/479304/coding-challenge-string-to-date Here it is. Of course normally the code would be without prints and put in function, but this is enough for now for me. There could also be normalization from '/' separated form not producing ambiguous …

1
269
Member Avatar for nouth

I wonder what you want to do for the array, why you want to change it to worse representation? You can easily count/filter number with numpy functions. Have you read/browsed the [relevant numpy documentation](http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html)? http://docs.scipy.org/doc/numpy/reference/routines.sort.html Tony

Member Avatar for nouth
0
1K
Member Avatar for giancan

You have read http://wiki.wxpython.org/wxPython%20by%20Example#A_Full_Example , haven't you?

Member Avatar for giancan
0
245
Member Avatar for TrustyTony

If I want to search for some tag, and I have not any so tagged post in front of me, how I open posts with that tag? I know that if I have one similarly tagged I can only click the tag.

Member Avatar for pritaeas
0
242
Member Avatar for joseph_7

> global tot_words tot_words = len(words_dict) global correct correct = 0 These declarations do not make sense as they are on top level, not inside function. If you must use globals, put them at very beginning of functions. Usually classes are better option. I rearrange your lines standard way and …

Member Avatar for TrustyTony
0
162
Member Avatar for ZZucker

I would get rid of the glob.glob totally as we deal only with ends. filenames = [path for path in os.listdir(directory) if path.endswith(('.py', '.txt'))]

Member Avatar for snippsat
0
519
Member Avatar for acrocephalus

Here is example code printing selected file: [CODE]import os from Tkinter import Tk import tkFileDialog toplevel = Tk() toplevel.withdraw() filename = tkFileDialog.askopenfilename() if os.path.isfile(filename): for line in open(filename,'r'): print line, else: print 'No file chosen' raw_input('Ready, push Enter') [/CODE]

Member Avatar for ronkalycarlos
0
18K
Member Avatar for TrustyTony

I am looking for alternatives to setup a server in work place which does not allow to setup new software to computers to check and reserve rooms for meetings both through local network computers or possible from home / on the move. I of course would like to have thy …

Member Avatar for TrustyTony
0
295
Member Avatar for london-G

Looks little like prolog, I see that first is out of bounds base case, others area the recursion cases. [Here]( http://stackoverflow.com/questions/10063516/list-length-inserting-element) is discussion how in Prolog you would define inserting, maybe it gives you some help. You would only need to check that length of beginning part is asked number, …

Member Avatar for Hiroshe
0
287
Member Avatar for TrustyTony

To continue[ my quiz series](http://www.daniweb.com/search/query/0?q=%22quiz+of+the%22+pytony#gsc.tab=0&gsc.q=%22quiz%20of%20the%22%20pytony&gsc.page=1), explain what happens with this code (how you would name this action and is there other way to get same result), why, and what is actually the value of `a` at end. a = ['a', 'b','e'] a[2:2] = ['c', 'd']

Member Avatar for TrustyTony
0
256
Member Avatar for almando
Member Avatar for danae.gordon9
Member Avatar for harrykokil

The loop counter in Vegaseat's code should not be x and the assignment should be moved out of the loop # Tkinter animate via canvas.move(obj, xAmount, yAmount) import Tkinter as tk import time root = tk.Tk() canvas = tk.Canvas(root, width=400, height=400) canvas.pack() # canvas.create_rectangle(x0, y0, x1, y1, option, ... ) …

Member Avatar for TrustyTony
0
10K
Member Avatar for SumTingWong59

Please use Code from the posting menu and post your code inline. Make first not growing snake, the add collision detect. Basically list of places where snake is could be good idea, then you just remove one end and add one cordinate for head, when snake grows you leave the …

Member Avatar for TrustyTony
0
934
Member Avatar for vuze

Import should be mostly at beginning, so import application class Mapsframe(wx.Frame): def __init__(self): pass class Example(wx.Frame,listmix.ColumnSorterMixin): def __init__(self, *args, **kwargs): super(Example, self).__init__(*args, **kwargs) self.InitUI() def InitUI(self): pass def onItemSelected(self,event): frame = Mapsframe() application.one_function(frame) #e.g.

Member Avatar for TrustyTony
0
274

The End.