[Tutor] Expected indented block error
Hi i have been working on a currency converter for school and i have been having a hard time with this syntax error Expected indented block and i don't understand why it isn't working. i am fairly new to Python thus my sloppy and unfinished code hope you can help :) My code - v_fallback = 1 while v_fallback == 1: print(Please enter your current currency) v_current = input() if v_current == (USD or usd or US Dollars or us dollars): print(Please enter the name of the currency you wish to convert to) print(Your options are GBP, EUR, INR, AUD, CAD, AED or BACK to return to the Main Menu) v_final = input() if v_final ==(GBP or gpb): if v_final == (EUR or eur): if v_final == (INR or inr): if v_final == (AUD or aud): if v_final == (CAD or cad): if v_final == (AED or aed): if v_final == (BACK or back): else: print (ERROR - Please enter a valid currency, if incorrect currency is entered again program will close) print(Your options are GBP, EUR, INR, AUD, CAD, AED or BACK to return to the main menu) v_final = input() if v_final == (GBP or gbp): if v_final == (EUR or eur): if v_final == (INR or inr): if v_final == (AUD or aud): if v_final ==(CAD or cad): if v_final == (AED or aed): if v_final == (BACK or back): else print (ERROR - Program will close): v_fallback = 0 #if v_current == (GBP or gbp or pounds or Pounds or pounds sterling): #v_exrate = #v_fallback = 0 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] AntiSpam measures circumventing
Hello, I shared some assembly code (microcontrollers) and I had a comment wit my e-mail address for contact purposes. Supposing my name is John Doe and the e-mail is john@hotmail.com, my e-mail was written like this: removemejohn.dospames...@removemehotmail.com' With a note saying to remove the capital letters. Now, I wrote this : for character in my_string: ... if (character == character.upper()) and (character !='@') and (character != '.'): ... my_string = my_string.replace(character,'') And the end result was john@hotmail.com. Is there a better way to do that ? Without using regular expressions (Looked *really* ugly and it doesn't really make sense, unlike the few lines I've written, which are obvious even to a beginner like me). I obviously don't like SPAM, but I just thought If I were a spammer, how would I go about it. Eventually, some algorithm of detecting the johndotdoeathotmaildotcom must exist. Also, what would in your opinion make it *harder* for a non-human to retrieve the original e-mail address? Maybe a function with no inverse function ? Generating an image that can't be converted back to text, etc.. If this is off-topic, you can just answer the what is a better way to do that part. Thanks, -- ~Jugurtha Hadjar, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code
Can anyone please help me figure out what I am NOT doing to make this program work properly.PLEASE !! I need to be able to take the user input that is entered in the two graphical boxes of the first window and evaluate it to generate a graph chart which is suppose to display in the second window. I am totally at a loss for what I am NOT doing, and I know it is something so simple that I am overlooking because I am making this harder that what it most likely really is. But I just cannot get it to work properly. Please HELP !!! Help me understand what I am doing wrong and how to fix it. I believe I am on the right path but I'm becoming frustrated and discouraged. I have attached a copy of the code I've compiled so far. # futval_graph2.py from graphics import * def main(): # Introduction print(This program plots the growth of a 10-year investment.) win = GraphWin(Growth of 10-Year Investment, 400, 300) win.setCoords(0.0, 0.0, 3.0, 4.0) # Draw the interface Text(Point(1,3),Enter principal:).draw(win) input = Entry(Point(2,3), 5) input.setText(0.00) input.draw(win) principal = eval(input.getText()) Text(Point(1.10,2.5),Input APR:).draw(win) input2 = Entry(Point(2,2.5), 5) input2.setText(0.0) input2.draw(win) apr = eval(input2.getText()) output = Text(Point(0,0),) output.draw(win) button = Text(Point(1.5 ,1.65),Graph It) button.draw(win) Rectangle(Point(.5,2), Point(2.5,1.25)).draw(win) # wait for a mouse click win.getMouse() win = GraphWin(Investment Growth Chart, 320, 240) win.setBackground(white) win.setCoords(-1.75,-200, 11.5, 10400) # Create a graphics window with labels on left edge Text(Point(-1, 0), ' 0.0K').draw(win) Text(Point(-1, 2000), ' 2.5K').draw(win) Text(Point(-1, 5000), ' 5.0K').draw(win) Text(Point(-1, 7500), ' 7.5k').draw(win) Text(Point(-1, 1), '10.0K').draw(win) # Draw bar for initial principal bar = Rectangle(Point(0, 0), Point(1, principal + apr)) bar.setFill(green) bar.setWidth(2) bar.draw(win) # Draw a bar for each subsequent year for year in range(1, 11): bar = Rectangle(Point(year, 0), Point(year+1, principal)) bar.setFill(green) bar.setWidth(2) bar.draw(win) win.getMouse() win.close() main()___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Suds, Lxml - sending an xml request
i'm probably very annoying and boring with these python web service :)and sorry for the previous message reply subject,wont happen again... the thing is, i'm provided with some service provider documentation, including xml request example, xml response example, wsdl file for the protocol defintion, and xsd file for every request type. i've played around with LXML and SUDS, and i got this : xml parsing (i don't really know if i need this, but i made it just to see how it works ): try: from lxml import etree except ImportError: import xml.etree.ElementTree as etree # document = etree.parse(HotelValuedAvailRQ.xml) root = document.getroot() #namespaces used xmlns = '' xsi = '{http://www.hotelbeds.com/schemas/2005/06/messages}' # user = document.find('//{namespace}User'.format(namespace=namespace)) user.text = '' #set hotelbeds user(text) password = document.find('//{namespace}Password'.format(namespace=namespace)) password.text = '' #set hotelbeds password(text) language = document.find('//{namespace}Language'.format(namespace=namespace)) language.text = '' #set hotelbeds response language(text) #set number of pages for xml response(attribute) PaginationData = root[2].set('pageNumber', '4') #set check in date, format :'20130509' CheckInDate = root[3].set('date', '') #set check out date CheckOutDate = root[4].set('date', '') #set dest code, set dest type Destination = root[5].set('code', ''); root[5].set('type', '') #set the room count RoomCount = document.find('//{namespace}RoomCount'.format(namespace=namespace)) RoomCount.text = '' #set number of adults AdultCount = document.find('//{namespace}AdultCount'.format(namespace=namespace)) RoomCount.text = '' #set number of children ChildCount = document.find('//{namespace}ChildCount'.format(namespace=namespace)) ChildCount.text = '3' document.write('HotelValuedAvailRQ.xml') print '---Changes saved' and i also made this, some suds experiment : import logging logging.basicConfig(level = logging.INFO) logging.getLogger('suds.client').setLevel(logging.DEBUG) #logging.getLogger('suds.wsdl').setLevel(logging.DEBUG) #logging.getLogger('suds.transport').setLevel(logging.DEBUG) #logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG) logging.getLogger('suds.wsse').setLevel(logging.DEBUG) from suds.client import Client url = 'http://xxx.xxx.xxx.xxx/appservices/ws/FrontendService?wsdl' client = Client(url) print client which gives me following result : Suds ( https://fedorahosted.org/suds/ ) version: 0.4 GA build: R699-20100913 Service ( FrontendServiceService ) tns= http://www.hotelbeds.com/wsdl/2005/06; Prefixes (0) Ports (1): (FrontendService) Methods (34): cancelProtectionAdd(xs:anyType cancelProtectionAdd, ) cancelProtectionRemove(xs:anyType cancelProtectionRemove, ) getCancelProtectionAvail(xs:anyType getCancelProtectionAvail, ) getCarCountryList(xs:anyType getCarCountryList, ) getCarInfoSet(xs:anyType getCarInfoSet, ) getCarValuedAvail(xs:anyType getCarValuedAvail, ) getCountryList(xs:anyType getCountryList, ) getDestinationGroupList(xs:anyType getDestinationGroupList, ) getHotelBoardGroupList(xs:anyType getHotelBoardGroupList, ) getHotelBoardList(xs:anyType getHotelBoardList, ) getHotelCategoryGroupList(xs:anyType getHotelCategoryGroupList, ) getHotelCategoryList(xs:anyType getHotelCategoryList, ) getHotelCountryList(xs:anyType getHotelCountryList, ) getHotelDetail(xs:anyType getHotelDetail, ) getHotelList(xs:anyType getHotelList, ) getHotelRoomTypeGroupList(xs:anyType getHotelRoomTypeGroupList, ) getHotelValuedAvail(xs:anyType getHotelValuedAvail, ) getIncomingOfficeDetail(xs:anyType getIncomingOfficeDetail, ) getIncomingOfficeList(xs:anyType getIncomingOfficeList, ) getPurchaseDetail(xs:anyType getPurchaseDetail, ) getPurchaseList(xs:anyType getPurchaseList, ) getTicketAvail(xs:anyType getTicketAvail, ) getTicketClassificationList(xs:anyType getTicketClassificationList, ) getTicketCountryList(xs:anyType getTicketCountryList, ) getTicketDetail(xs:anyType getTicketDetail, ) getTicketValuation(xs:anyType getTicketValuation, ) getTransferCountryList(xs:anyType getTransferCountryList, ) getTransferValuedAvail(xs:anyType getTransferValuedAvail, ) getZoneGroupList(xs:anyType getZoneGroupList, ) purchaseCancel(xs:anyType purchaseCancel, ) purchaseConfirm(xs:anyType purchaseConfirm, )
Re: [Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code
On 21/09/13 04:26, znx...@yahoo.com wrote: Can anyone please help me figure out what I am NOT doing to make this program work properly.PLEASE !! First you need to tell us what graphics module you are using since there is no standard library module by that name. Second, you should probably ask for help on their forum since this list is really for those learning Python and its standard library. However, if we know the library we might be able to help or someone may have some experience. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] AntiSpam measures circumventing
On 2013-09-20 15:50, Jugurtha Hadjar wrote: I obviously don't like SPAM, but I just thought If I were a spammer, how would I go about it. You wouldn't, it's not effective to do this. You would just grab plain text e-mail addresses and leave it at that, anyone who tries to obfuscate their e-mail address is not worth spamming anyway. pgp6xsHUzQJiW.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Expected indented block error
On 21/09/13 23:44, Arron Sutcliffe wrote: Hi i have been working on a currency converter for school and i have been having a hard time with this syntax error Expected indented block and i don't understand why it isn't working. It tells you, it's expecting an indented block... v_fallback = 1 while v_fallback == 1: print(Please enter your current currency) v_current = input() if v_current == (USD or usd or US Dollars or us dollars): print(Please enter the name of the currency you wish to convert to) print(Your options are GBP, EUR, INR, AUD, CAD, AED or BACK to return to the Main Menu) v_final = input() if v_final ==(GBP or gpb): Python is expecting an indented block of code to do something when the if is true. So eoitrher you put some code here or... if v_final == (EUR or eur): You indent this line. But thats probably a bad idea. if v_final == (INR or inr): if v_final == (AUD or aud): if v_final == (CAD or cad): BTW these lines are almost certainly not doing what you think they are. This is not testing whether v_final is one of the values in the if tet, it is testing whether v_final has the same truth(boolewan0 vale as the expression (str1 or str2) which is always True. You probably want something like if v_final.upper() == GBP: # do something or, more likely in this case: if v_final.upper() in (GBP, INR, AUD, ...other values): #do this if v_final == (AED or aed): if v_final == (BACK or back): else: print (ERROR - Please enter a valid currency, if incorrect currency is entered again program will close) print(Your options are GBP, EUR, INR, AUD, CAD, AED or BACK to return to the main menu) v_final = input() if v_final == (GBP or gbp): if v_final == (EUR or eur): if v_final == (INR or inr): if v_final == (AUD or aud): if v_final ==(CAD or cad): if v_final == (AED or aed): if v_final == (BACK or back): else print (ERROR - Program will close): v_fallback = 0 And there is a programming principle called DRY (Don't Repeat Yourself). You have the same set of tests here as above. Rather than limit the user to 2 goes you could wrap the tests into a while loop and only have them once. That way there is never any risk of them getting out of step with each other. (You could also encapsulate them in a function but you might not have covered functions yet!) HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] AntiSpam measures circumventing
- Original Message - From: Jugurtha Hadjar jugurtha.had...@gmail.com To: tutor@python.org Cc: Sent: Friday, September 20, 2013 4:50 PM Subject: [Tutor] AntiSpam measures circumventing Hello, I shared some assembly code (microcontrollers) and I had a comment wit my e-mail address for contact purposes. Supposing my name is John Doe and the e-mail is john@hotmail.com, my e-mail was written like this: removemejohn.dospames...@removemehotmail.com' With a note saying to remove the capital letters. Now, I wrote this : for character in my_string: ... if (character == character.upper()) and (character !='@') and (character != '.'): ... my_string = my_string.replace(character,'') And the end result was john@hotmail.com. Is there a better way to do that ? Without using regular expressions (Looked *really* ugly and it doesn't really make sense, unlike the few lines I've written, which are obvious even to a beginner like me). I used this a while ago. It's not Python, but it's effective: http://www.jottings.com/obfuscator/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] ImportError: No module named '_sysconfigdata_m'
Hi, I just wanted to type git status in my Linux terminal but I made a typo and I got a long Python 3.3 traceback message. Just curious: What does it mean? gigt status Traceback (most recent call last): File /usr/lib/python3.3/site.py, line 631, in module main() File /usr/lib/python3.3/site.py, line 616, in main known_paths = addusersitepackages(known_paths) File /usr/lib/python3.3/site.py, line 284, in addusersitepackages user_site = getusersitepackages() File /usr/lib/python3.3/site.py, line 260, in getusersitepackages user_base = getuserbase() # this will also set USER_BASE File /usr/lib/python3.3/site.py, line 250, in getuserbase USER_BASE = get_config_var('userbase') File /usr/lib/python3.3/sysconfig.py, line 580, in get_config_var return get_config_vars().get(name) File /usr/lib/python3.3/sysconfig.py, line 530, in get_config_vars _init_posix(_CONFIG_VARS) File /usr/lib/python3.3/sysconfig.py, line 403, in _init_posix from _sysconfigdata import build_time_vars File /usr/lib/python3.3/_sysconfigdata.py, line 6, in module from _sysconfigdata_m import * ImportError: No module named '_sysconfigdata_m' Thank you! Regards, Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Suds, Lxml - sending an xml request
Hi, On 20 September 2013 14:25, Ismar Sehic i.she...@gmail.com wrote: i'm probably very annoying and boring with these python web service :)and sorry for the previous message reply subject,wont happen again... the thing is, i'm provided with some service provider documentation, including xml request example, xml response example, wsdl file for the protocol defintion, and xsd file for every request type. You should not need to mess with lxml yourself if you're using a SOAP library like suds. Also, you might try SOAPpy, or alternatively, try ZSI if you can get it working -- the project seems kind of dead and not recently updated and I seem to remember it was rather fiddly to get it working last time I had to work with it. (That said I might add that we've had good success with ZSI. Usefully, it can generate wrapper classes for your WSDL which means you get a concrete native Python representation that you can refer to, of the webservice interface you're trying to work with. SOAPpy and other more recent frameworks takes a more minimalist approach and does everything dynamically which can sometimes make it a bit tricky to work with a new interface.) Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ImportError: No module named '_sysconfigdata_m'
On Mon, Sep 23, 2013 at 3:28 PM, Albert-Jan Roskam fo...@yahoo.com wrote: I just wanted to type git status in my Linux terminal but I made a typo and I got a long Python 3.3 traceback message. Just curious: What does it mean? gigt status Traceback (most recent call last): gigt? Why is that trying to run Python? File /usr/lib/python3.3/_sysconfigdata.py, line 6, in module from _sysconfigdata_m import * ImportError: No module named '_sysconfigdata_m' _sysconfigdata.build_time_vars updates sysconfig._CONFIG_VARS. build_time_vars was parsed from pyconfig.h when Python was built: http://hg.python.org/cpython/file/d047928ae3f6/Lib/sysconfig.py#l364 http://hg.python.org/cpython/file/d047928ae3f6/pyconfig.h.in On Debian systems the dict is actually stored in the platform-specific module _sysconfigdata_m. I doubt it's a sys.path issue since the platform subdirectory is baked in to the interpreter binary. Check that the module exists: /usr/lib/python3.3/plat-x86_64-linux-gnu/_sysconfigdata_m.py or /usr/lib/python3.3/plat-i386-linux-gnu/_sysconfigdata_m.py ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code (znx...@yahoo.com)
Hello, I have attached a copy of the code I've compiled so far. Next time just post the code in here, I think that's the general consensus around here. You should only attach it or use a pastebin if it's really really long. Considering that usually the only valid entries here are snippets of code you've isolated that do not work (functions/methods...), code that gets posted here is usually not too long. Anyhow the graphics.py module is unbeknownst to me, but I presume you're reffering to this one: http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/graphics.html What you're doing wrong is your input: principal = eval(input.getText()) apr = eval(input2.getText()) Those commands are in order, however their position in programing is not. Let's examine: 1. you draw your input screen and define standard inputs for boxes 2. during the drawing session you read in values for which you have provided input boxes 3. you plot the values in a bar graph. When this runs it goes like this: 1. you draw your input screen, set values in input boxes to 0.0 and 0.0 2. apr and principal get set to 0.0 and 0.0 3. plot graph and values and of course every single bar gets ploted to 0, because those are the values of your inputs. If there is no principal to add apr to there is no net result. You should make it so that apr and principal get set AFTER the initial screen drawing session but BEFORE plotting, therefore after the mouse-click. You're also making a mistake of not actually changing any values as the year progresses: bar = Rectangle(Point(year, 0), Point(year+1, principal)) every bar will have the same height, that of the inputed principal value. I don't know if it's encouraged here or not, to give straight away answers, but here it goes anyway because I think znx is missing couple of other things as well: To sort out the wrong inputing move the eval() lines after the win.getMouse() statement, preferably right before the for loop statement. Your principal grows each year by the value of apr, so if you have a 1000$ in the bank and the bank awards you with 500$ each year (good luck with that) then by the end of the first year you should have 1500$, by the end of the 2nd year 2000$ because the 1st year becomes the principal for the 2nd year, by 3rd year it's 2500$ and so on To introduce the changing values you have to have a new variable to store the increased original value, let's call that variable newvalue. Then you have to increase the value of the new variable every complete step of the for loop. Each full circle of for loop should see at least 1 newvalue = newvalue +apr (or newvalue+=apr in short). This solution removes the need for the # Draw bar for initial principal set of orders so delete it: # read values in input boxes AFTER the button click principal = eval(input.getText()) apr = eval(input2.getText()) #create new value that you'll increase every year by apr newvalue = principal+apr #this is the net money by the end of 1st year # Draw a bar for each subsequent year for year in range(0, 11): #by going from 0 you don't have to specifically plot 1st year bar = Rectangle(Point(year, 0), Point(year+1, newvalue)) newvalue = newvalue+apr bar.setFill(green) bar.setWidth(2) #I don't know if this serves any purpose because the width of your bar is defined with year to year+1 values. Maybe it's the line width? bar.draw(win) and that should do it. For a test run use print statement to check that the for loop does what you want it too and use simple numbers as principal=1000 and apr=500, you should get 1500, 2000, 2500.. (This looked a lot like a fixed interest rate assignment so I guess that's the purpose, note that because of the set scale of the graph you should always use larger numbers because smaller ones will not be visible). You can make your y axis change by the value of input if you: 1. read input after button click but before setting the scale 2. set scale from 0 to maximal achievable value + some aditional height that you can see the entire graph (p.s. maximal achievable value is principal+final_year*apr, so in your case, principal+11*apr+500 [for spacing]) 3. plot the rest Good luck, Dino ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ImportError: No module named '_sysconfigdata_m'
On Mon, Sep 23, 2013 at 12:28:10PM -0700, Albert-Jan Roskam wrote: Hi, I just wanted to type git status in my Linux terminal but I made a typo and I got a long Python 3.3 traceback message. Just curious: What does it mean? Unless this was at the Python prompt, it's not really a Python question. It's a question about your Linux installation, and why gigt ends up calling Python. Start with: man gigt which gigt locate gigt to try to identify what it is. If nothing relevant comes up, that suggests that your Linux system is set up to try to help when you mistype a command. E.g. on one Ubuntu system, I get this: steve@flora:~$ gigt No command 'gigt' found, did you mean: Command 'gitg' from package 'gitg' (universe) Command 'gist' from package 'yorick' (universe) Command 'gift' from package 'gnuift' (universe) Command 'git' from package 'git-core' (main) gigt: command not found I don't know the technology behind this feature, but it may be built using Python. That explains why you're going a Python traceback. Which implies that you've broken the system Python. Very few Linux distros use Python 3.3 as their system Python. Your error suggests that you've replaced the expected Python installation, probably 2.7, with 3.3 instead of installing in parallel. That's not a good idea. You can test this by su'ing to some user other than yourself, to ensure you have a clean environment, and then run python -V to see the version. If I do this as both the steve and root users, you can see I get two different versions: [steve@ando ~]$ python -V Python 2.7.2 [steve@ando ~]$ su - Password: [root@ando ~]# python -V Python 2.4.3 That's because the steve user has a line in my .bashrc file that sets an alias python=python2.7, while the system Python on this machine is Python 2.4. Last but not least, the error message you get hints that your Python 3.3 installation may be broken. What happens if you try to run it normally? The error ends with: File /usr/lib/python3.3/sysconfig.py, line 403, in _init_posix from _sysconfigdata import build_time_vars File /usr/lib/python3.3/_sysconfigdata.py, line 6, in module from _sysconfigdata_m import * ImportError: No module named '_sysconfigdata_m' If you can reliably reproduce this error, it should be reported as a bug. Assuming you didn't break it yourself :-) I note that in my version of Python 3.3, line 6 of _sysconfigdata is not an import, and the line from _sysconfigdata_m import * does not exist anywhere in the file. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor