880 Posted Topics

Member Avatar for lewashby

[cx_Freeze ](http://cx-freeze.sourceforge.net/) works Python 2 and 3. [gui2exe](https://code.google.com/p/gui2exe/) for all installers into a GUI interface. As mention by Gribouillis on Linux it's ofen no problem to just give away `.py` files. In my project [wx_nrk](https://bitbucket.org/snippsat/wx_nrk) for downloading all on norwegian TV. I choiced to compiled to `exe` for Windows user …

Member Avatar for TrustyTony
0
325
Member Avatar for Waseemaburakia

> Does this work for what you are asking? nichom your function is not `recursive` wish is the task here. Look at pyTony soultion.

Member Avatar for fonzali
0
217
Member Avatar for fheppell

Make a `list index out of range` error. >>> lst = [1,2,3] >>> lst[2] 3 >>> lst[3] Traceback (most recnt call last): File "<interactive input>", line 1, in <module> IndexError: list index out of range So it should be easy to understand if you look at list(print or repr). Then …

Member Avatar for snippsat
0
2K
Member Avatar for srinu_1

You first post. http://www.daniweb.com/software-development/python/threads/470301/problem-in-copying-domain-name-from-one-notepad-to-another-using-regex You have postet more info about the task,but it still not as clear as it should be. You can try this. import re with open('1.txt') as f1,open('2.txt') as f2,open('result.txt', 'w') as f_out: f1 = re.findall(r'rhs="(.*)"', f1.read()) f2 = re.findall(r'rhs="(.*)"', f2.read()) diff = [i for i in …

Member Avatar for snippsat
0
374
Member Avatar for srinu_1

It is better to use `re.finditer` when iterate over text and save to file. Look like this. import re data = '''\ line2 jdsbvbsf line3 <match name="item1" rhs="domain.com"></match> line4 <match name="item2" rhs="domainn.com"></match> line5 <match name="item2" rhs="1010data.com"></match>''' with open('result.txt', 'w') as f_out: for match in re.finditer(r'rhs="(.*)"', data): f_out.write('{}\n'.format(match.group(1))) '''Output--> domain.com domainn.com …

Member Avatar for srinu_1
0
381
Member Avatar for Frank15

> but absolutelly no doubt that building web on PHP will be faster/easier, That is of course a lot bullshit for someone that use Python. I use Python for web development and don't like messy PHP. [PHP: a fractal of bad design](http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/) I wrote a little about Python and web …

Member Avatar for kindo
0
324
Member Avatar for [V]

If you remove `re.IGNORECASE` look better? import re data = '''\ Amiloride-sensitive cation channel, ASIC3 (also called BNC1 or MDEG) which is an acid-sensitive (proton-gated)''' cleantext = re.sub(r'\(|\)|\[|\]', '' ,data) cleantext = re.sub(r'\w{1,}( |-)(gated|sensitive)', '' ,cleantext) print cleantext.strip() '''Output--> cation channel, ASIC3 also called BNC1 or MDEG which is an …

Member Avatar for snippsat
0
195
Member Avatar for dany12

> Hy I would like to know what python gui framework, I can use that will be compatible cross platform You can use most Python GUI framework as the work fine crossplatform or with minor changes. Talking about Wxpython,PyQt(PySide),PyGTK and build in Tkinter. kivy is new in Python GUI world,can …

Member Avatar for dany12
0
348
Member Avatar for Lost&Found

Your code doesn't make sense as it are now. If you are gone use `sys.argv`,you know that means running script from command line and pass in argument from command line? #site_check.py import sys def printWebsite(url): print "url for sys.argv {}".format(url) def main(): printWebsite(sys.argv[1]) if __name__ == '__main__': main() Running from …

Member Avatar for Gribouillis
0
311
Member Avatar for AARTI SHRIVAS

> 1.is is used for web development Python is great for all web stuff you can think of. Is normal to use [Web Framework](https://wiki.python.org/moin/WebFrameworks) when making websites. Django is the most known and has good documentation,some sites run bye Django [djangosites](http://www.djangosites.org/). Some info about setup Apache with mod_wsgi/mod_python [here](http://stackoverflow.com/questions/219110/how-python-web-frameworks-wsgi-and-cgi-fit-together) [HOWTO …

Member Avatar for snippsat
0
440
Member Avatar for venkaaaaat

> if there are more number of parameters, out of which we need to print version and type only > > can you please help with the code to get out this You have to post an example of how the other parameters look. There are many ways to do …

Member Avatar for manohar1111
0
594
Member Avatar for Py New BB

Python has a [scheduler](http://docs.python.org/2/library/sched.html#module-sched) module,wish is a option to OS scheduler like Cron or Windows task scheduler. I have used it's some times and it work well sleeping in background and do work only when it shall. One positive aspect is that is crossplatform. So this will run every 2 …

Member Avatar for snippsat
0
165
Member Avatar for bryann

[The Problem with Integer Division](http://python-history.blogspot.no/2009/03/problem-with-integer-division.html) Not much else to say if you read that post. One tips is to use `from __future__ import division` for Python 2.x. Python 3.x has made chage to integer-division. #Python 2.7 >>> 10 / 3 3 >>> from __future__ import division >>> 10 / 3 …

Member Avatar for bryann
0
321
Member Avatar for Remy the cook

Give an example or link og what you try to extract/parse. As mention by krystosan it's XML data,and there are good tool for this in Python. And library that is only for parsing RSS like [Universal Feed Parser](http://pythonhosted.org/feedparser/) I like both Beautifulsoup and lxml. A quick demo with Beautifulsoup. from …

Member Avatar for Remy the cook
0
2K
Member Avatar for pythonnewbie16

Reapting code(answer). Class or function's is a must to stucture code when it get longer. This is maybe something you need to learn. Some tips to get rid of all that if's. Here use dictionary and convert all input to lowercase(`lower()`) Then you dont need this `'run' or answer=='Run':` Another …

Member Avatar for snippsat
0
397
Member Avatar for pythonnewbie16

Start bye testing your convert function,it's not working. def covert_temperature(fahrenheit): '''Convert fahrenheit to celsius''' return (fahrenheit - 32) * 5.0/9.0 Test: >>> covert_temperature(1) -17.22222222222222 >>> covert_temperature(50) 10.0 So working correct. == Checks if the value of two operands are equal or not. You can not have it your function and …

Member Avatar for HiHe
0
940
Member Avatar for LucyLogic

First page 8 post down. [Generating count for odd & even](http://www.daniweb.com/software-development/python/threads/466671/generating-count-for-odd-even)

Member Avatar for vegaseat
0
510
Member Avatar for booicu

Some hint and look at differnt ways to count. For counting this is a standar way. import random n = 100 even = 0 for item in range(n): if random.randint(1,n) % 2 == 0: even += 1 print('Even numer count is {}\nOdd number count is {}'.format(even, n - even)) """Output--> …

Member Avatar for vegaseat
0
3K
Member Avatar for dany12

> Php will be still around because it can work on almost any host. > > So the future is php python javascript. Yes all of this languages will be there in the future. I wish that PHP would be less popular because it's a messy language,but i dont think …

Member Avatar for dany12
0
749
Member Avatar for krystosan

The import statement will return the top level module of a package. You can try this. varhelp = __import__("sys").path But be careful and try to keep "magic stuff" away from import statement. [import(doc)](http://docs.python.org/2/library/functions.html#__import__) > Note This is an advanced function that is not needed in everyday Python programming, unlike importlib.import_module().

Member Avatar for woooee
0
188
Member Avatar for HiHe

> A tuple uses much less memory than a list. And should be faster. C:\>python -m timeit (1,2,3,4) 10000000 loops, best of 3: 0.0226 usec per loop C:\>python -m timeit [1,2,3,4] 10000000 loops, best of 3: 0.194 usec per loop Yes tuple are faster than list.

Member Avatar for vegaseat
0
684
Member Avatar for ChicagoBears2012_1

>>> from collections import OrderedDict >>> s = "Mathematics".upper() >>> ''.join(OrderedDict.fromkeys(s)) 'MATHEICS'

Member Avatar for snippsat
0
270
Member Avatar for nitin1

Why are you using Python 2.4 wish is 8 year old? Code works for Python 2,even if there some ugly stuff in it. Post full Traceback.

Member Avatar for nitin1
0
206
Member Avatar for happygeek

richieking this was an 5 years old post. As Gribouillis posted python has never break anything before release of python 3. Python 3 has been planned for many years,and is of course the right descion for the evolution of this great language. But the are very clear that python 2 …

Member Avatar for vegaseat
0
743
Member Avatar for toll_booth

Download numpy for Python 3.3 [here](http://www.lfd.uci.edu/~gohlke/pythonlibs/),try again.

Member Avatar for vegaseat
0
340
Member Avatar for Krontical

You are trying to install pyhook for Python 2.7, wish you don't have installed. Many modules work still only for python 2.x that's why most of us still you Python 2. Pyhook works for python 3.3 you can find a version [here](http://www.lfd.uci.edu/~gohlke/pythonlibs/).

Member Avatar for snippsat
0
730
Member Avatar for Bhavya scripted

Date and time measurement is a complex area full of tricky problems and unexpected edge-cases. This is why we have and should use libraries for this. It can of course be fun to do this manually,but also painful if you try for a long periods of time like this. Just …

Member Avatar for TrustyTony
1
473
Member Avatar for Rebecca_2

> sorry, but what prevents the code from only ever reaching the first '****optimisation achieved****' and counting that line repeatedly? Here is an another way to this. Here i want to get file name and count back,and also correct line number back. file_1.txt: fire fox **** Optimisation achieved **** file_2.txt: …

Member Avatar for snippsat
0
286
Member Avatar for james.lu.75491856

Use urlretrieve,something like this. import winsound try: # Python2 from urllib import urlretrieve except ImportError: # Python3 from urllib.request import urlretrieve def play(sound): winsound.PlaySound(sound, winsound.SND_FILENAME) # Download wave file and save to disk url = "http://www.villagegeek.com/downloads/webwavs/adios.wav" filename = url.strip().split('/')[-1] urlretrieve(url, filename) print("Sound saved as {}".format(filename)) # Play wave file play(filename)

Member Avatar for snippsat
0
1K
Member Avatar for farmwife

> How about this someone told me about: The code is terrible and not working. > There must be a shorter way of doing that too :) def word_reverser(word_in): return word_in[::-1] user_input = raw_input('Type anything and hit enter: ') d = word_reverser(user_input) print("Eek, what's this?! ==> {}".format(d))

Member Avatar for james.lu.75491856
-1
178
Member Avatar for Tcll

> IMO, VS2010 with PythonTools 1.5 is the best IDE. Say that you mean that,don't speak for everyone. > PyScripter has alot of glamour, but it doesn't have an interactive interpreter PyScripter has always had a interactive interpreter. Spyder is ok,and istall with [winpython](https://code.google.com/p/winpython/),to get a lot of tools as …

Member Avatar for Tcll
0
658
Member Avatar for Hikki_Passion

Now do python have strong parser like lxml and BeautifulSoup,that do job like this much easier. [CODE]>>> from BeautifulSoup import BeautifulSoup >>> html = '''<img align=top src="photos/horton.JPG" alt="Image of StG instructor (Diane Horton)">', "src"''' >>> soup = BeautifulSoup(html) >>> tag = soup.find('img') >>> tag['src'] u'photos/horton.JPG'[/CODE]

Member Avatar for james.lu.75491856
0
1K
Member Avatar for lewashby

> I need to do simple things like list the file and folders in a directory 'ls' and change director 'cd'. I found these two pages that looked promesing but I still didn't fine what I was looking for. Any ideas? Maybe you need to broaden your Python knowledge,because this …

Member Avatar for lewashby
0
146
Member Avatar for nytman

Can use isinstance. >>> weight = float(raw_input("enter the weight: ")) enter the weight: 100.0 >>> weight 100.0 >>> type(weight) <type 'float'> >>> isinstance(weight, float) True >>> isinstance(weight, int) False >>> weight = 50 >>> isinstance(weight, float) False >>> #If you want both int and float to be True >>> isinstance(weight, …

Member Avatar for nytman
0
19K
Member Avatar for mgold

Most of the Design Patterns are build languages features. We use them all the times without thinking about this,a good video about it [Python Design Patterns 1](https://www.youtube.com/watch?v=Er5K_nR5lDQ) Just a couple more videos that are really good if you new to Python. [Transforming Code into Beautiful, Idiomatic Python](http://pyvideo.org/video/1780/transforming-code-into-beautiful-idiomatic-pytho) [Python's Class Development …

Member Avatar for snippsat
0
178
Member Avatar for epicSHOOTER236

Alternative to Gribouillis good use of itertools. search_word = 'card 1' with open('filename.txt') as f: for line in f: if search_word in line: print 'Next line after: {} is {}'.format(search_word, next(f).strip()) print next(f).strip() '''Output--> Next line after: card 1 is ball red ''' You can you `next()` to jump line …

Member Avatar for epicSHOOTER236
0
281
Member Avatar for red23

epicSHOOTER236 i think the point is running Python(.py) from notpad++,and not do this manual stuff. http://npppythonscript.sourceforge.net/ For windows i like much better editor that is made for Pythnon like [Pyscripter](http://code.google.com/p/pyscripter/) or [Spyder](http://code.google.com/p/spyderlib/)

Member Avatar for JasonHippy
0
3K
Member Avatar for toniann.midori

The list show only integer,so why convert at all. >>> lst = [120, [10, 20, 30]] >>> lst[0] 120 >>> lst[1] [10, 20, 30] >>> type(lst[0]) <type 'int'> >>> balance, withdrawal = lst[0], lst[1] >>> balance 120 >>> withdrawal [10, 20, 30]

Member Avatar for toniann.midori
0
3K
Member Avatar for Cducks

>>> 'Hi! Puctuation counts as a character.'[::2] 'H!Pcuto onsa hrce.' Python slice notation. 'Hi! Puctuation counts as a character.'[start:stop:step] Start and stop(deafault :) start(H) and stop(.) If step is positve we are moving forwards starting at(H)(if the value of 'step' is ommited, it defaults to +1)

Member Avatar for snippsat
0
170
Member Avatar for 26bm

Both py2exe and cx_freeze(works also for python 3) works fine. If you search daniweb both i and vegaseat and more people has working examples. IronPython can also be used to make exe. http://www.daniweb.com/software-development/python/code/455497/ironpython-revisited-99-bottlse-of-beer My lastet example of using cx_freeze. http://www.daniweb.com/software-development/python/threads/454877/win32com-error-with-cx_freeze-#post1975985 A coulple more links. http://www.daniweb.com/software-development/python/threads/449706/how-to-convert-my-python-program-into-exe-file http://www.daniweb.com/software-development/python/threads/366232/can-you-compile-an-exe-in-python

Member Avatar for james.lu.75491856
0
381
Member Avatar for LincyDaniel

`name = sys.argv[1]` means that you most give argument from Command-line. `run.py something` if you dont give argument from Commad-line you get `IndexError: list index out of range` Read about `sys.argv` Your code is messy. else: pass else: pass else: pass This is not good at all.

Member Avatar for james.lu.75491856
0
165
Member Avatar for Empireryan

> What is the purpose of this? I wonder about this to. > I'm wondering if it is possible to pass formatted strings to function arguments. Yes a formatted string is still a string and function can take most datatypes. I dont see the point of splitting the format option …

Member Avatar for snippsat
0
223
Member Avatar for krystosan

Shorter. >>> strng = '1002-1004,1 1444' >>> re.findall(r'\W', strng) ['-', ',', ' '] Or the same without regex. >>> strng = '1002-1004,1 1444' >>> [c for c in strng if c in ['-', ',', ' ']] ['-', ',', ' ']

Member Avatar for krystosan
1
211
Member Avatar for Jacklittle01

>>> import platform >>> platform.architecture()[0] '32bit' py2exe-0.6.9.**win32**-py2.7.exe Check that you python version and py2exe are both 32bit or both 64bit. I keep all to 32bit in Python,and i have 64bit windows 7.

Member Avatar for snippsat
0
72
Member Avatar for wolf29

This should work. import csv with open('test.csv', 'rb') as f,open('out.csv', 'wb') as f_out: reader = csv.reader(f) writer = csv.writer(f_out) for row in reader: writer.writerow((row[3], row[5]))

Member Avatar for wolf29
0
17K
Member Avatar for RockJake28

As posted over itertools izip is ok to use and fast. Python has also build in [zip](http://docs.python.org/2/library/functions.html#zip) >>> zip(names,surnames) [('Jake', 'Cowton'), ('Ben', 'Fielding'), ('Rob', 'Spenceley Jones')] --- for first,last in zip(names,surnames): print first,last Jake Cowton Ben Fielding Rob Spenceley Jones

Member Avatar for Lardmeister
0
328
Member Avatar for nouth

dir(__builtins__) #list of what's in the built-in namespace If you not sure do a simple test. You get a NameError if python can't find the name. >>> reload <built-in function reload> >>> my_reload Traceback (most recent call last): File "<interactive input>", line 1, in <module> NameError: name 'my_reload' is not …

Member Avatar for chriswelborn
1
631
Member Avatar for nouth

> I think import can be used to access functions from another .py file but I'm not sure and haven't used it yet Yes and here dos `if __name__ == "__main__":` play and important part. You have made a fantastic name multiplier code,and you whant to import it so you …

Member Avatar for nouth
0
508
Member Avatar for ytbyun

You should try to come up with some code,many just post there school task here and show no effort to solve it. When that said,here something you can look at. with open('people.txt') as f, open('names.txt', 'w') as f_out: lst = [i.split() for i in f] lst_diff = [x for x …

Member Avatar for snippsat
0
205
Member Avatar for otengkwaku
Member Avatar for snippsat
0
296

The End.