3,386 Posted Topics

Member Avatar for Fluffybunny

Why not ftp? Or basic http open? [CODE]data = open('OutputFile.txt').read() f = urllib2.urlopen(url, data)[/CODE]

Member Avatar for TrustyTony
0
2K
Member Avatar for vulcano224

I do not understand class without init also push code before pasting code.

Member Avatar for vegaseat
0
206
Member Avatar for pendo19

Maybe this consolised piece of code can help something: [CODE]def searchfilt(): text = raw_input('Please choose a highlighter search term:\n') for i, line in enumerate(["1280320019","u'Search Appointments at DkIT'", "u'https://recruit.ancheim.ie/dkit/rec/erq_search_package.search_form?p_company=1&p_internal_external=E&p_display_in_irish=N'", "Firefox History","Normal Time"]): if text in line: a,b,c = list(line.partition(text)) print(''.join((a,'<strong>',b,'</strong>',c))) ## c can have second hit else: print line searchfilt() [/CODE]

Member Avatar for TrustyTony
0
242
Member Avatar for Tommymac501

simple: [CODE]>>> a='Cadillac' >>> answer=[a] >>> answer ['Cadillac'] >>> b, = answer >>> b 'Cadillac' >>> [/CODE] b, means singleton tuple, tuple with one element,

Member Avatar for woooee
0
4K
Member Avatar for abcdr

Maybe the poster liked to have list containing integer length instead of the element for every element of the list. Then for line 5 use statement to return list of counts. What happens or is supposed to happen if the elements are numbers? Maybe len(str(element)) is better to add to …

Member Avatar for jcao219
0
100
Member Avatar for gonzigg

At least here is little refactoring to loop and function and usefull sum to terminal window: [CODE]from graphics import * def makeinput(win,i): #Item and Price input maker center2 = Point(50,50*i+50) label2 = Text(center2, "Item >>") label2.draw(win) input2 = Entry(Point(170,55+i*50), 20) input2.setText("item") input2.draw(win) centera = Point(350,50) labela = Text(centera, "Price >>") …

Member Avatar for gonzigg
0
4K
Member Avatar for hisan

[code]with open('binfile.dat', 'rb') as bf: bf.seek(10) open('out.dat', 'wb').write(bf.read(80))[/code] Something like this. This is untested as I am not with computer now. Maybe you must seek(9) and/or read(81).

Member Avatar for hisan
0
89
Member Avatar for pythonbegin

use statement like: [code]if this_key in my_dict: my_dict[this_key].add(this_value) else: my_dict[this_key] = {this_value}[/code]

Member Avatar for Beat_Slayer
0
3K
Member Avatar for pythonbegin

You can split records from \t and put first records to set and then same from other file and for each record which is in second file which has same key field put in result. Gribouillis did nicely that he checked for uniqueness of the keys as text file is …

Member Avatar for TrustyTony
0
775
Member Avatar for acrocephalus
Member Avatar for acrocephalus
0
361
Member Avatar for acrocephalus

[QUOTE=woooee;1285517]You would have to use Tkinter or one of the other toolkits. An example [url]http://tkinter.unpythonic.net/wiki/AutocompleteEntry[/url][/QUOTE] Broken link.

Member Avatar for cronos4d
0
92
Member Avatar for jenzilla

[CODE]import datetime today = datetime.date.today() time_to_stay = int(raw_input('Number of days you want to stay: ')) future = datetime.timedelta(days=time_to_stay) expire = today + future print(expire) [/CODE]

Member Avatar for jenzilla
0
3K
Member Avatar for spac_e

Also it is not very good choice to change the meaning of [URL="http://www.daniweb.com/code/snippet216520.html"]map function[/URL] to dictionary, even it is inside function. Could give you bad habit that bites back later.

Member Avatar for TrustyTony
0
80
Member Avatar for Gribouillis

I also think that the action of using int function or as hidden by round, is disruptive as it is very discontinuous by its very nature. Sometimes it is better to stay with integers and be clearly discontinuous. Same could be done, maybe by multiplying numbers by some constant before …

Member Avatar for Gribouillis
0
3K
Member Avatar for TrustyTony

Here is my practise with [URL="http://www.boggled.org/"]boggle [/URL]letter square non-overlapping word finder after some drastic debugging and cleaning. I think it is reasonable speed also. Comments wellcome.

Member Avatar for TrustyTony
0
1K
Member Avatar for fingerpainting

Could you post beginning of the original csv file or attach it from advanced view, manage attachments? I would guess that delimeter is ','

Member Avatar for fingerpainting
0
9K
Member Avatar for buddyalexander

EDIT: Code tags added I have just started to learn python (Learning Python), and I am trying to move some files to another folder that are over a week old. I keep getting an error about the files not existing. [CODE] import shutil, sys, time, os src = 'c:/users/wca36050/temp1' dst …

Member Avatar for TrustyTony
0
244
Member Avatar for abhijat

you must test for each number which is prime. You can stop checking when the prime**2 is bigger than maximum value of candidates. To be sure to find the 1000 use for example list of 100 000 truth values all True in beginning. Then take each prime*n (every nth) by …

Member Avatar for TrustyTony
0
1K
Member Avatar for faby

Corrected your finishing tag to (/code) from Queue import PriorityQueue #making the priority queue object pq = PriorityQueue() #making the different dictionaries firstDict = {'boy':'short', 'girl':'tall'} secondDict = {'man':'tall', 'woman':'short'} #putting the objects in the priorityQueue with a priority number pq.put(secondDict,2) pq.put(firstDict, 1) #printing the dictionary according to their priority …

Member Avatar for TrustyTony
0
2K
Member Avatar for wolfeater017
Member Avatar for wolfeater017
0
114
Member Avatar for murjam

You do not need to push even tab most times as reasonable editors know Python indention style, even 4 spaces is the default tab width. Mostly I hit this isssue when I try code in IDLE command line and want to copy it over to my program file.

Member Avatar for TrustyTony
0
157
Member Avatar for KirkK

In Python you can call the function, which is defined after another without forward definitions. However the function must be defined before main code calls it. It is bad practise to put main code before definitions except for some variable definitions. [CODE]def a(p): if p>4: b(p) else: print "a", def …

Member Avatar for TrustyTony
0
162
Member Avatar for abcdr

And for the beauty of recursion you can try: [CODE]def wordReverse(word): if not word: return word ## empty sequence is already reversed else: return word[-1]+wordReverse(word[:-1]) print wordReverse('Python newbie')[/CODE] And the classic "vegaseat's" [CODE]def wordReverse(word): return word[::-1] # -1 step from default start to default end [/CODE]

Member Avatar for TrustyTony
0
197
Member Avatar for kate2mba

Unfortunately the answer in snippsat's nice post is sorting alphabetically, not by length. Here fix and list comprehenision to do the same. [CODE]def wordPop(text, n): nwords = [] words = text.split() for word in words: if (len(word) >= n): nwords.append(word) return sorted(nwords, key=len, reverse= True ## if longest first ) …

Member Avatar for kate2mba
0
187
Member Avatar for Genre

Accepted wisdom in Python circles is not to use xml if it is not forced to you for compatibility with programs or systems out of your control.

Member Avatar for TrustyTony
0
99
Member Avatar for abcdr
Member Avatar for TrustyTony
0
451
Member Avatar for koffrig

You could divide the job in small enough pieces and check for parameter change and pause after each piece. You should separate parameter entering in separate thread so it stays active during execution.

Member Avatar for TrustyTony
0
159
Member Avatar for java_programmer
Member Avatar for newtri13
Member Avatar for obscurecoder

Code of how you generated and saved the database in first place, could be helpful. I don't know so much, but others could get better idea for the reason of this happening.

Member Avatar for TrustyTony
0
74
Member Avatar for bettersaid

Good place for mac installers seem to be for example: [url]http://pythonmac.org/packages/py25-fat/index.html[/url] Seems to be for elder version of Python though.

Member Avatar for TrustyTony
0
144
Member Avatar for Anteater7171
Member Avatar for bob47910

[QUOTE=bob47910;1282262]If I created Tkinter window with some text that filled the whole window and now wanted to replace the window with a new text, is there a way to refresh the window? For Example: a= 100 win= Tk() win.geometry("500x300") while a > 0: if a%2 == 0: lbl = Label …

Member Avatar for TrustyTony
0
11K
Member Avatar for parijat24

If the input value is in variable info: [CODE]>>> info.split('\n',1) ['>sp|P20905|5HT1R_DROME 5-hydroxytryptamine receptor 1 OS=Drosophila melanogaster GN=5-HT7 PE=2 SV=1', 'MALSGQDWRRHQSHRQHRNHRTQGNHQKLISTATLTLFVLFLSSWIAYAAGKATVPAPLV\nEGETESATSQDFNSSSAFLGAIASASSTGSGSGSGSGSGSGSGSGSYGLASMNSSPIAIV\nSYQGITSSNLGDSNTTLVPLSDTPLLLEEFAAGEFVLPPLTSIFVSIVLLIVILGTVVGN\nVLVCIAVCMVRKLRRPCNYLLVSLALSDLCVALLVMPMALLYEVLEKWNFGPLLCDIWVS\nFDVLCCTASILNLCAISVDRYLAITKPLEYGVKRTPRRMMLCVGIVWLAAACISLPPLLI\nLGNEHEDEEGQPICTVCQNFAYQIYATLGSFYIPLSVMLFVYYQIFRAARRIVLEEKRAQ\nTHLQQALNGTGSPSAPQAPPLGHTELASSGNGQRHSSVGNTSLTYSTCGGLSSGGGALAG\nHGSGGGVSGSTGLLGSPHHKKLRFQLAKEKKASTTLGIIMSAFTVCWLPFFILALIRPFE\nTMHVPASLSSLFLWLGYANSLLNPIIYATLNRDFRKPFQEILYFRCSSLNTMMRENYYQD\nQYGEPPSQRVMLGDERHGARESFLD'] >>[/CODE]

Member Avatar for parijat24
0
141
Member Avatar for Krstevski

Your code is not in context but this seems to function normally for me in Python 3.1 [CODE]def fun(): try: fdjalsd # bla bla... except Exception as e: # here I got error message "Invalid Syntax" in the comma print('Handler, error:',e) return False print(fun()) """Output: Handler, error: global name 'fdjalsd' …

Member Avatar for Krstevski
0
343
Member Avatar for bettersaid

[URL="http://embraceubuntu.com/2006/12/16/gnome-open-open-anything-from-the-command-line/"]This link[/URL] says: [QUOTE]Simply put, the command gnome-open opens the item specified by the url with the preferred GNOME app for that file/mime-type. In a sense, this command resembles the universal “open” command on Mac OSX.[/QUOTE] So Mac is supposed to have [iCODE]open[/iCODE] command

Member Avatar for TrustyTony
0
157
Member Avatar for ultimatebuster

[CODE]try: value=int('surely not number') except ValueError as e: print e[/CODE]

Member Avatar for Gribouillis
0
213
Member Avatar for andrewtrench

The SQL statement is string, so you can probably do something like: [CODE]num_title=54 headerline=','.join("Header%i" %i for i in range(num_title)) ## take in reality from header sql="CREATE TABLE IF NOT EXISTS (%s)" % headerline print sql [/CODE]

Member Avatar for TrustyTony
0
582
Member Avatar for bpatt22

Like this seems to work, but I do not know if it is easiest. If you use Python 3, surely there must be cleaner alternative using dictionary comprehensions. [CODE]import operator d1 = dict() d1[0] = 1 d1[1] = 2 d1[2] = 2 maxValue = max(d1) print [key for key in …

Member Avatar for TrustyTony
0
8K
Member Avatar for bettersaid

For most needs Python list correspond with array. You can split fields by line.split('\t'). You can test if value is in field by in and usualy also strip and lower methods come handy.

Member Avatar for woooee
0
180
Member Avatar for G_S

Your running environment is Linux? What readline functions are you using? Some piece of example code, maybe? Have you tried the curses support? [URL="http://docs.activestate.com/activepython/2.5/python/curses/curses.html"]Curses Programming with Python[/URL]

Member Avatar for G_S
0
205
Member Avatar for lewashby

1) Because they are different modules: [CODE]>>> import Tkinter >>> Tkinter <module 'Tkinter' from 'D:\Python27\lib\lib-tk\Tkinter.pyc'> >>> import tkMessageBox >>> tkMessageBox <module 'tkMessageBox' from 'D:\Python27\lib\lib-tk\tkMessageBox.pyc'>[/CODE] Second question I don't know to answer.

Member Avatar for vegaseat
0
276
Member Avatar for parijat24

For example that first line of first file looks different format (bold finishing tag before but no starting tag), otherwise, is it so that yo want to pick identifier between > and | psoition 1:9, (>sp|P20905| > id = sp|P20905) and when it is found take start and end indexes …

Member Avatar for jcao219
0
198
Member Avatar for linuxoidoz

Is there not way to hide instead of close the window in QT? Then you could create window hidden and then only show it when needed and afterwards hide it again. If that window have different menus and even tool bar, I would call it different application and implement it …

Member Avatar for linuxoidoz
0
13K
Member Avatar for ultimatebuster

I do not know about regex magic so much, but here is my plain Python code, if it may help you: [CODE]sents= ('open red box with key','open red box','open box', 'open box with key') for sentence in sents: sentence = sentence.split() print sentence verb, obj = sentence.pop(0), sentence.pop(0) ## object …

Member Avatar for ultimatebuster
0
133
Member Avatar for job2

use: [CODE]for line in data_list: print(line)[/CODE] Python indexes start from 0 but you can add one to them when you need them or insert for example '' or [] as first (zeroth) element. You can use partition with two new lines to separate the groups in file first and split …

Member Avatar for TrustyTony
0
140
Member Avatar for TrustyTony

Check this out: [URL="http://www.lfd.uci.edu/~gohlke/pythonlibs/"]Unofficial Windows Binaries for Python Extension Packages[/URL]

0
92
Member Avatar for ultimatebuster

Generator is function which 'freezes' for every result and yields it, when next answer is requested function is 'unfrozen' with all the local state. When all answers are finished the iterator gives StopIteration exception and does not give more results. Sequences that are iterable have method called __iter__ and that …

Member Avatar for ultimatebuster
0
101
Member Avatar for wolfeater017

> this is what I have in my module Push the (CODE) button before pasting, please! import time print('Hello World!!!!') time.sleep(1) print ('what is your name?') name = input() a = ('Hello ') b = (' my name is com') string = a+name +b print (string) time.sleep(2) print('What is your …

Member Avatar for wolfeater017
0
1K
Member Avatar for prashanth s j
Member Avatar for TrustyTony
0
102

The End.