880 Posted Topics
Re: [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 … | |
Re: > Does this work for what you are asking? nichom your function is not `recursive` wish is the task here. Look at pyTony soultion. | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: > 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 … | |
Re: 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 … | |
Re: > 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 … | |
Re: 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 … | |
Re: > 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 … | |
Re: > 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 … | |
Re: 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 … | |
Re: [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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: First page 8 post down. [Generating count for odd & even](http://www.daniweb.com/software-development/python/threads/466671/generating-count-for-odd-even) | |
Re: 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--> … | |
Re: > 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 … | |
Re: 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(). | |
Re: > 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. | |
Re: >>> from collections import OrderedDict >>> s = "Mathematics".upper() >>> ''.join(OrderedDict.fromkeys(s)) 'MATHEICS' | |
Re: 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. | |
Re: 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 … | |
Re: Download numpy for Python 3.3 [here](http://www.lfd.uci.edu/~gohlke/pythonlibs/),try again. | |
Re: 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/). | |
Re: 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 … | |
![]() | Re: > 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: … |
Re: 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) | |
Re: > 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)) | |
Re: > 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 … | |
Re: 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] | |
Re: > 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 … | |
Re: 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, … | |
Re: 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 … | |
Re: 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 … | |
Re: 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/) | |
Re: 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] | |
Re: >>> '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) | |
Re: 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 | |
Re: `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. | |
Re: > 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 … | |
Re: 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 ['-', ',', ' ']] ['-', ',', ' '] | |
Re: >>> 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. | |
Re: 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])) | |
Re: 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 | |
Re: 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 … | |
Re: > 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 … | |
Re: 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 … | |
Re: ["Good enough" is good enough!](http://pyvideo.org/video/1738/good-enough-is-good-enough) |
The End.