- Strength to Increase Rep
- +14
- Strength to Decrease Rep
- -3
- Upvotes Received
- 469
- Posts with Upvotes
- 366
- Upvoting Members
- 148
- Downvotes Received
- 17
- Posts with Downvotes
- 14
- Downvoting Members
- 10
880 Posted Topics
Re: To make some futher i improvement's. All code is now in functions, explanation is moved into function so it work as doc-string(then it's possible to use `help()` on functions). I have removed all `global` statement which it's not good at all. Functions should be isolated code,that takes argument's and return … | |
Re: Hi see if this help you. [CODE]>>> str_input = '''AATTCCGGTTT CCTTAACCCCC''' >>> str_input 'AATTCCGGTTT\nCCTTAACCCCC' >>> x = str_input.replace ('\n', '') >>> x 'AATTCCGGTTTCCTTAACCCCC' >>> [/CODE] | |
Re: [QUOTE]but it says its not right, whats wrong with it?[/QUOTE] The code works,python always give you Traceback. Post Traceback next time. Run of code. [CODE]>>> generateNumber(0,10,2) [0, 2, 4, 6, 8, 10] >>> generateNumber(20,0,-3) [20, 17, 14, 11, 8, 5, 2] >>> [/CODE] | |
Re: This was very bad,not worth anyone times. The gui builder for wxpython could be better,but they are much better than this. | |
Re: Dont use bold character for everthing. Here is and example you can look at and try out. [CODE]#average.py #saved in python dir from __future__ import division def average(seq_in): if isinstance(seq_in, (list, tuple)): return sum(seq_in) / len(seq_in) else: return 'Input can only be list or tuple' [/CODE] So we save this … | |
Re: You are doing some strange stuff. Do you get urllib to work for this site? import urllib2 url = "http://www.blah.fi/" read_url = urllib2.urlopen(url).read() print read_url #403 error This site are blocking use of urllib. I had to use [Requests](http://docs.python-requests.org/en/latest/) to get source code. You can use BeautifulSoup to get all … | |
Re: You dont need to convert code just write it in python. I could of course convert it to look exactly like C++ over,but that had been stupid. Because python dos most stuff a lot eaiser than C/C++. [CODE] print 'Enter numers,use q to stop' l = [] while True: user_input … | |
Re: You have some mistake,and use code tag. See if this help. [CODE]def main(): phrase = input("Enter a sentence:") words = phrase.split() #Forget () wordCount = len(words) print("The total word count is: %s" % wordCount) #You have to include wordCount in print main()[/CODE] | |
Re: Something like this? import wx class MyFrame(wx.Frame): def __init__(self, parent, mytitle, mysize): wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize) #--Panel so it look good on all platforms self.panel = wx.Panel(self) self.datepick = wx.DatePickerCtrl(self.panel,-1, pos=(20,15), style=wx.DP_DROPDOWN|wx.DP_SHOWCENTURY) self.datepick.Bind(wx.EVT_DATE_CHANGED, self.onAction) self.label = wx.StaticText(self.panel,-1,"", pos=(20,50)) def onAction(self, event): '''Process data from picked date''' selected = self.datepick.GetValue() … | |
Re: I have done some tesing and got it to work(windows 7 Ultimate) First my test code. #sound_test.py import pyttsx import time from datetime import date from datetime import datetime engine = pyttsx.init() date = date.today() time_now = datetime.now() date = date.strftime("%A %d %B") time_now = time_now.strftime('%H:%M:%S') engine.say('The date is {} … | |
Re: [CODE]import wx class my_window(wx.Frame): def __init__(self, parent, id): #error __int__ wx.Frame.__init__(self,parent,id,'My Window', size=(300,200)) #Panel for frame self.panel = wx.Panel(self) self.SetBackgroundColour('blue') if __name__ == "__main__": app=wx.PySimpleApp() frame=my_window(parent=None,id=-1) frame.Show() app.MainLoop()[/CODE] | |
Re: As posted by @dashing.adamhughes there are made a lot of stuff that can help you with this,another eksp is [pyfasta](http://pypi.python.org/pypi/pyfasta/) > How to get the start and end position of a particular pattern You can use `re.finditer` for this. >>> import re >>> s = '11ATGC1111ATGC11111ATGC' >>> p = 'ATGC' … | |
Re: Look like you use python 3 [CODE]>>> #Python3 has only input that return a string >>> user_input = input('Give me a number: ') Give me a number: 10 >>> user_input '10' >>> type(user_input) <class 'str'> >>> print 'Your number was %s' % (user_input) SyntaxError: invalid syntax (<pyshell#4>, line 1) >>> … | |
Re: [QUOTE]what has fileHandle been replaced with in python 3.1[/QUOTE] FileHandle is just a variable name used by vega. You can use whatever name you want. Here is the same code for python 3 [CODE] # Testet work for python 3 # read a text file as a list of lines … | |
Re: Start to read where you post,this is the python part of Daniweb. Post in VB forum. [QUOTE] Trying hard since 1 week... Cn u plz provide me a code for d same ??? I got submissions in few days... Pllzzz.... Thanx !![/QUOTE] And nowone post finsih code,if you dont show … | |
Re: The same for me "InBox" and "Send Message" has not work after change to Dazah. Both give `Rate limit exceeded: Please try your request again in a few minutes.. ` Same on all pc. Has to copy cookie to from working login,to other computer just to get login to work. … | |
Re: I see you have get good help from Gribouillis. As a note `with open` was new in python 2.5. python 2.2.1 is really old. Alternatives is to write your own parser that works for your files,it`s not so hard. If i use config file postet by Grib. cfg_dict = {} … | |
Re: Use wheel as posted bye Gribouillis. PyMongo has C depencies so to avoid this [Installing from source on Windows](https://api.mongodb.com/python/current/installation.html#installing-from-source-on-windows) Go [here](http://www.lfd.uci.edu/~gohlke/pythonlibs/#pymongo),when dowloaded your version. Do e.g **pip install pymongo-3.3.0-cp35-cp35m-win32.whl** Wheel(.whl) has all C depencies packed,no need to compile. | |
Re: To set it up more,correct and fix error. Capitale letters in `method == 'POST'` Have remove GET to avoid to confusion. foo\ app.py templates\ index.htm `app.py` from flask import Flask,redirect,url_for,request,render_template app = Flask (__name__) @app.route('/') def my_form(): return render_template("index.html") @app.route('/suc/<name>') def suc(name): return "hello Boss %s" % name @app.route('/login', methods=['POST']) … | |
Re: Your pasting of xml is a mess:) The best is to use [Beautiful Soup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/)/lxml. E.g from bs4 import BeautifulSoup xml ='''\ <?xml version="1.0" encoding="UTF-8"?> <note> <to>Hello</to> <from>wold</from> <msg timestamp="20160817 12:46:42.520" level="INFO">Info on CPU</msg> </note>''' #soup = BeautifulSoup(open("your.xml"), 'html.parser') #Read from a file soup = BeautifulSoup(xml, 'html.parser') msg = soup.find('msg') print(msg.text) … | |
Re: > I like python and I wanted to give it a try at web programming but the setup and management is too difficult. I'll just go back to php. It's not so difficult,and you do not need stuff like LAMP. Django and Flask has build in web-server this you use … | |
Re: It's in [http.cookie](https://docs.python.org/3/library/http.cookies.html) for Python 3.x. So import is `from http import cookies` For all about HTTP use [Requests](http://docs.python-requests.org/en/master/) >>> import requests >>> url = 'http://httpbin.org/cookies' >>> cookies = dict(cookies='are good to eat') >>> r = requests.get(url, cookies=cookies) >>> print(r.text) { "cookies": { "cookies": "are good to eat" } } | |
Re: > what if I need to take seperate nosetests html report for each file.. How can I do that ? Yes as bash script looping over files will work,or a Python script with `subprocess`. There are build into nose to test all files that start `test`. So naming your files … | |
Re: Command you has to be string and you concatenate "line" inside `os.system()`. So if i have i list of words and want to now lenght of each word, i can use linux command `expr length`. The command get executed on each line of words.txt. import os import time f = … | |
Re: The problem can be solved before give data to Pandas. As mention over there are lot of cases to think about. I would have made up rules with regex. Example. >>> import re >>> s = "Richard Wayne Van Dyke" >>> re.split(r"\s*(?:(?:[a-zA-Z]')|(Van \w.*))", s, re.I)[:-1] ['Richard Wayne', 'Van Dyke'] >>> … | |
Re: A more normal way to use __int__ (constructor) in a python class. And just some point that a class is storeing variables in a dictionary. [CODE]from math import sqrt class ageName(object): '''class to represent a person''' def __init__(self, name, age): self.name = name self.age = age worker1 = ageName('jon', 40) … | |
Re: Just some points,always use raw string [B]r' '[/B] with regex. For email validation re.match(),for extracting re.search, re.findall(). There is no simple soultion for this,diffrent RFC standard set what is a valid email. This has been up in several forum,here is a good one you can read. [url]http://stackoverflow.com/questions/201323/what-is-the-best-regular-expression-for-validating-email-addresses[/url] Just a quick … | |
Re: >Is that what gets returned if the letter is not in the dictionary? So if it can't find the letter it adds 0? Yes,and you can also return a more meaningful message. Here in function and return value out. def record(word): return { "t": 1, "f": 1, "c": 1, "b": … | |
![]() | Re: >Beautiful Soup is for python . i am using windows and vb.net You should find a parser for vb.net,like [Html Agility Pack ](http://htmlagilitypack.codeplex.com/) >i have been doing some research. >and found out about Regular expressions..... Regex i bad tool for html,read this funny answer bye [bobince ](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). >gives me pratice … |
Re: I have to say that i don't like this tagging system at all. Maybe it's get better when i get used to it,but i am not sure. In Python part of the old forum we had sticky thread, do we really need to search for those threads now? Or can … | |
Re: >Where should I host a python project on linux? I'm sure there'd be multiple choices. So, Where would you host it & on what circumstances? Github,Bitbucket... If you mean web-host,pythonanywhere,Heroku,Webfaction,Digital ocean... >I understand that virtualenv creates a virtual environment separate from others. But, why should one need it? Do we … | |
Re: >I just started to learn python few days ago. This is a small program I made to practise. Ok,some points. names = ['(1) Sphere','(2) Right Circular Cone','(3) Cylinder'] x=0 while x < 3: print(names[x]) x +=1 This is not the way to loop in Python. You just iterate over list … | |
Re: >I am trying to convert a file to a dictionary here is the contents of the file, You can data keep structure bye using serialization, then you don't have to struggle to recreate structure from a string. JSON is preferably over Pickle. import json record = { 'Name': 'DragonMastur', 'Hand': … | |
Re: >A must read Or a better [read ](http://docs.python-requests.org/en/latest/user/advanced/#proxies) You should really look into and use [Requests](http://docs.python-requests.org/en/latest/) Shailang. | |
Re: >really don't even know which webpage language I should use HTML, PHP, SQL something else?. You can of course use Python. Micro-framework like [Flask](http://flask.pocoo.org) can be a good place to start. Python has bigger Framework like [Django](https://www.djangoproject.com/), [web2py](http://www.web2py.com/) or CMS like [Django-cms](http://www.django-cms.org/en/). These has a lot of tools,and can be … | |
Re: If you search for cola you see this url. `https://datacvr.virk.dk/data/visninger?soeg=cola&type=Alle` Generate own search url's. >>> url = 'https://datacvr.virk.dk/data/visninger?soeg={}&type=Alle' >>> search_lst = ['car', 'train'] >>> for item in search_lst: ... print(url.format(item)) ... https://datacvr.virk.dk/data/visninger?soeg=car&type=Alle https://datacvr.virk.dk/data/visninger?soeg=train&type=Alle E.g of take out some data,here all title text when search for cola. import requests from bs4 … | |
Re: It work's for me when i do a little test,using Pyhon 3.4.2. mytxt1.txt: http://ascii.cl?parameter=%22Click+on+%27URL+Decode%27%21%22 login=bob%40%3CSCRipt%3Ealert%28Paros%29%3C%2FscrIPT%3E.parosproxy.org http://ascii.cl?parameter=%22Click+on+%27URL+Decode%27%21%22 login=bob%40%3CSCRipt%3Ealert%28Paros%29%3C%2FscrIPT%3E.parosproxy.org outtxt1.txt: http://ascii.cl?parameter="Click+on+'URL+Decode'!" login=bob@<SCRipt>alert(Paros)</scrIPT>.parosproxy.org http://ascii.cl?parameter="Click+on+'URL+Decode'!" login=bob@<SCRipt>alert(Paros)</scrIPT>.parosproxy.org | |
Re: from bs4 import BeautifulSoup import urllib2 html = ''' <img src="smiley.gif" alt="Smiley face" height="42" width="42">''' soup = BeautifulSoup(html) images = soup.find('img') print(images['src']) #smiley.gif | |
Re: >Also, strings in Python 3 are unicode so enocde and decode are not necessary. That's only true if text is already inside Python 3. Here we are talking about taking text from outside into Python 3, then we must define a encoding like utf-8,latin-1..., or it will give an error … | |
Re: Python do have build in libraries that can generate key which hold cryptographic strength. Her use [SHA-256](https://en.wikipedia.org/wiki/SHA-2) >>> import hashlib >>> hashlib.sha256(b"licence key").hexdigest() 'ad26f374a671d9add68a110b31769667691a54ed599e791b5c8eb065b16c9ddc' Will also metion [cryptography](https://github.com/pyca/cryptography) which is the future for cryptographic in Python. | |
Re: 2 books that are ok. [url]http://www.amazon.com/Beginning-Python-Professional-Magnus-Hetland/dp/1590599829/ref=sr_1_5?ie=UTF8&qid=1304460522&sr=8-5[/url] [url]http://www.amazon.com/Practical-Programming-Introduction-Pragmatic-Programmers/dp/1934356271/ref=sr_1_14?ie=UTF8&qid=1304460522&sr=8-14[/url] Reading starting python on site,a lot of good example. [url]http://www.daniweb.com/software-development/python/threads/20774[/url] [QUOTE]So,I have like 3-4 months to learn python and i wanna be really good at it[/QUOTE] You get the basic in 3-4 months,really good take long time. | |
Re: The most Pythonic `[::-1]` There is also reversed used with join(). Python34 handels Unicode good if you get Persian language correct decoded into Python34. In Python34 *are all strings a sequences of Unicode characters*. Just so you know,there is a big difference between Unicode handling Python 2 and 3. >>> … | |
Re: Kind off help whit some clear messages. [CODE]>>> we_dot_do_homework_if_no_effort_is_shown = 2 >>> 1 % we_dot_do_homework_if_no_effort_is_shown 1 >>> 2 % we_dot_do_homework_if_no_effort_is_shown 0 >>> 3 % we_dot_do_homework_if_no_effort_is_shown 1 >>> 4 % we_dot_do_homework_if_no_effort_is_shown 0 >>> stupid = 3 >>> show_effort = 4 >>> if stupid % we_dot_do_homework_if_no_effort_is_shown == 1: print'Odd' else: print 'even' … | |
Re: lxml need to be compiled,and for Python3.4 you most have Visual Studio C++ 2010(Windows). But there is an easier way,go to [Gohlke](http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml) pre-compiled wheel. Download `lxml‑3.4.4‑cp34‑none‑win32.whl` place it in `C:\python34\Scripts` folder. Start *cmd* navigate to `C:\python34\Scripts` folder. Then do `pip install lxml‑3.4.4‑cp34‑none‑win32.whl`. As info so is [pip](https://pip.pypa.io/en/stable/) pre-install(Scripts folder) on … | |
Re: Here is a hint. >>> user_input = 'The quick brown fox jumps over a lazy dog' >>> word_lst = user_input.split() >>> word_lst ['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'a', 'lazy', 'dog'] >>> len(word_lst) 9 >>> [len(c) for c in word_lst] [3, 5, 5, 3, 5, 4, 1, 4, 3] sum([len(c) … | |
Re: wudie47 read your [post](https://www.daniweb.com/software-development/python/threads/497089/file-name-as-a-string-parameter),just 1 day old, vegaseat did answer with the preferred way `os.path.splitext()`. >>> import os >>> filename = 'python.exe' >>> os.path.splitext(filename) ('python', '.exe') >>> os.path.splitext(filename)[-1] '.exe' >>> name, extension = os.path.splitext(filename) >>> name 'python' >>> extension '.exe' | |
Re: Need to see code to,and not just Traceback. Do `print(ser)` and `print(type(ser))`,then i think you see that's `ser` is an integer and not a fileobject. To create same Traceback. >>> ser = 5 >>> ser.readline() (most recent call last): File "<interactive input>", line 1, in <module> AttributeError: 'int' object has … | |
Re: There is also a [markdown2](https://github.com/trentm/python-markdown2) module. import markdown2 markdown = """\ # Hello, how are you I'm fine, thank you I know that it is not so **hard** but for me it's not so *easy* What is ##this? How about `*this*`? **it *wor`k`s!*** Let me put a bold link: [**stuff**](http://41.media.tumblr.com/49a58542fd70b8ca39b5bd0d9c9c53aa/tumblr_nob40mvTN41tb9nzio1_500.jpg) … | |
Re: A good technique to understand code is to break it up in smaller parts. For this is interactive interpreter great to us, also us `print()` in code on places you wonder what's happends. So lets say you wonder about `deque(maxlen=history)`. >>> from collections import deque >>> lst = [1, 2, … | |
Re: [QUOTE]I was wondering if there are any GUI toolkits in python that create native-looking windows in Windows 7[/QUOTE] Wxpython-PyQt dont have the ugly and native-looking that Tkinter has on all windows version. Tkinter look better on linux,mac. I postet a wxpython picture here. [url]http://www.daniweb.com/forums/thread252780.html[/url] Wxpython are a very good gui-toolkit … |
The End.