This is the code in pyCharm app on Linux Ubuntu
#1/usr/bin/python
def main(msg):
//Print a Message
print(msg)
main("Hello People")
I keep getting an error.
This is the video course I am following:
https://www.youtube.com/watch?v=wBp0Rb-ZJak
At the 3:37:00 mark is where it's supposed to refresh, but because of my error it will not.
Here is a screenshot of the code and error.
http://s1227.photobucket.com/user/MrGHLover/media/Screenshot%20from%202017-09-10%2023-36-52.png.html?sort=3&o=0
It is the same in the video but I can't figure it out.
Commenting by '//' is not allowed in python. Use '#' for commenting.
You can comment a line in Python using #. Or you can (kind of) create a multi-line comment using '''<some long string>""".//` Isn't valid Python.
Related
This is my second beginner python course, so I'm learning! For most things I'm working with Python notebooks because I feel it has more flexibility. The actual program is Coursera. I recently transferred the following code from python notebooks (that worked fine) back to Coursera, and I'm getting syntax errors. Not the first time. How do I avoid this? Looking for any advice.
"TabError: inconsistent use of tabs and spaces in indentation"
def email_list(domains):
emails = []
for provider, user in domains.items():
for each_user in user:
new_user=("{}#{} ".format(each_user,provider))
emails.append(new_user)
return(emails)
print(email_list({"gmail.com": ["clark.kent", "diana.prince", "peter.parker"], "yahoo.com": ["barbara.gordon", "jean.grey"], "hotmail.com": ["bruce.wayne"]}))
I have faced such problems in the past and here is what I did, after pasting your code in Coursera, try deleting every space and tab from your code and retype them for example, delete the spaces in the def line until you have this line
def email_list(domains):emails = []
after this line pressing return or enter right after the colon will give you the right indentation and hopefully, your code will run smoothly.
I am trying to create an "if" statement. But it comes back with an error. I have tried the same statement in pycharm and it works.
I use jupyter notebook so that it tells my any errors every line. I don't know what I'm doing wrong please help.
staffid1 = input('Input your Staff id here ...')
staffid2 = input('Re-enter your staff id here to confirm...')
if staffid1 == staffid2:
print('correct, searching database')
else:
print('invalid Staff id')
print('Error #1')
is it something I'm doing.
error-
File "<ipython-input-17-76bd76303e16>", line 1
if staffid1 == Staffid2:
^
SyntaxError: unexpected EOF while parsing
thankyou in advance
Staffid2 is capitalised in your error, but not in your original code. It shouldn't cause this exact error but hard to know what's going on if there are differences like this.
As written, your initial code runs fine for me in Jupyter.
It would be useful if you post the whole code exactly as you are running it in Jupyter to avoid these types of issues if you are still having problems...
I have the lines of code
import IPython
IPython.display.Audio(url="http://www.1happybirthday.com/PlaySong/Anna",embed=True,autoplay=True)
And I'm not really sure what's wrong. I am using try.jupyter.org to run my code, and this is within if statements. The notebook is also taking in user inputs and printing outputs. It gives no error, but just doesn't show up/start playing. I'm not really sure what's wrong.
Any help would be appreciated. Thanks!
First you should try it without the if statement. Just the two lines you mention above. This will still not work, because your URL does point to an HTML page instead of a sound file. In your case the correct URL would be 'https://s3-us-west-2.amazonaws.com/1hbcf/Anna.mp3'.
The Audio object which you are creating, will only be displayed if it is the last statement in a notebook cell. See my Python intro for details. If you want to use it within an if clause, you can use IPython.display.display() like this:
url = 'https://s3-us-west-2.amazonaws.com/1hbcf/Anna.mp3'
if 3 < 5:
IPython.display.display(IPython.display.Audio(url=url, autoplay=True))
else:
print('Hello!')
So I am just learning how to code and Im using pygtk to make a gui for a irc bot that im working on. The bot as some fun commands and stuf, but what im really here for is that I print the chat messages into a textbuffer and it makes memory go up, wich really isnt a problem unless you have a huge ammount of messages or want this to be on all the time. But with this problems in mind I wanted the bot to when he reached like 500 messages in the textbuffer(or 500 lines) he would delete the first 250 from the text buffer so that it would keep the memory usage down and still plenty of messages to read to whoever was using the gui.
My problem is that I dont really know how to do this, if I use iters they will become useless when delete the 250 lines because i've changed the textbuffer, and I also tried to use marks but it does look like I know how to use them...
HALP PLOX! xD
Code can be found here. The textbuffer is located inside run.py and is named chatbuffer.
Solved it Kappa
I use this for deletion:
if chatbuffer.get_line_count() > 10:
chatbuffer.delete(chatbuffer.get_iter_at_line(0), chatbuffer.get_iter_at_line(251))
And instead of defining inters like:
end_inter = chatbuffer.get_end_inter()
I just straigth up use:
chatbuffer.get_end_inter()
Like this:
chatbuffer.insert(chatbuffer.get_end_iter(), user + " > " + message + "\n")
EDIT: WELL IM DUMB I created a whole another questin because of an error that I encouuntered after this because I tested this with 10 lines and deleting 5 and forgot to change it to 500 on the final code. gtk-error **: gtk_text_btree_previous_line ran out of lines aborting
I'm using web2py to create a page where I search for books based on title/author/keyword/etc. and ISBN, and I can't seem to figure out how to use isbntools in the webapp. I'm sure it's something basic that I'm missing out on, but this is the first webapp that I've ever created, and it's for a class project. This is the related portion of my controller:
from isbntools import *
def index():
form=SQLFORM.factory(
Field('title',label='Try entering a title:'),
Field('author',label='Or an author:'),
Field('ISBN',label='Even better if you have the ISBN'),
Field('fromDate',label='When is the earliest the book might have come out?'),
Field('toDate',label='...and the latest?'))
if form.process().accepted:
titledata = isbn_goom form.vars.title bibtex
authordata = isbn_goom form.vars.author bibtex
isbndata = isbn_meta merge form.vars.ISBN bibtex
print(titledata)
print(authordata)
print(isbndata)
return dict(form=form)
This is a portion of the ticket information I'm getting back:
Error ticket for "Bibbly"
Ticket ID
96.255.27.81.2014-05-01.21-50-27.f66e0b53-b5bd-4621-8dbd-b6f30e8a6af1
invalid syntax (default.py, line 21)
Version
web2py™ Version 2.8.2-stable+timestamp.2013.11.28.13.54.07
Python Python 2.7.5+: /usr/local/bin/uwsgi (prefix: /usr)
Traceback
line 21
titledata = isbn_goom "form.vars.title" bibtex
^
SyntaxError: invalid syntax
isbm_goom is a command line script. Is that what you want?! (you cannot use it in your code like that!)
I suggests you use the most recent version of isbntools and adapt this snipet
from isbntools.contrib.modules.goom import goom
from isbntools.dev.fmt import fmtbib
...
titledata = goom.query(form.vars.title)
for r in titledata:
print((fmtbib('bibtex', r)))
Since python is complaining about a syntax error, it means it's about the literal code you've written. The Python interpreter can't grasp what you mean because you've specified something "impossible" in the language. In this case it's about the white-space after isbn_goom and form.vars.title. Since i don't know and don't see any declaration concerning isbn_goom i assume it's from the isbntools library. To try the library it may be best to learn about it in a separate console session on your own machine. See the pypi page for some examples.
On resolving syntax errors: You can try editing the code in any decent code editor and it will give you hints on these kinds of errors. The default python editor Idle that comes with any default installation would be great.