Your code tells me that you are using Python2.
Where is your start?
Your code tells me that you are using Python2.
Where is your start?
Creative answering machine messages:
"You have reached the CPX-2000 Voice Blackmail System. Your voice
patterns are now being digitally encoded and stored for later use. Once this is
done, our computers will be able to use the sound of YOUR voice for
literally thousands of illegal and immoral purposes. There is no charge
for this initial consultation. However, our staff of professional
extortionists will contact you in the near future to further explain the
benefits of our service, and to arrange for your schedule of payments.
Remember to speak clearly at the sound of the tone. Thank you."
Writing your own IDE, here is a hint on how to do this sort of thing:
http://www.daniweb.com/software-development/python/code/445504/an-almost-ide-wxpython
I would use the PySide GUI toolkit, since wxPython is a mess with Python3.
The Eric IDE is full featured and written in Python:
http://eric-ide.python-projects.org/
For a beginner the nimble IDLE that comes with your Python installation is probably best.
In your case def print_func( par ):
argument par could have other more decriptive names, just make sure you don't use builtin Python function names.
For guidelines on writing Python code see:
http://docs.activestate.com/activepython/2.5/peps/pep-0008.html
Actually using string formatting would be the most pythonic way:
num1 = int(raw_input("Enter an integer"))
num2 = int(raw_input("Enter a second integer"))
num3 = int(raw_input("Enter a third integer"))
ans = num1 + num2 + num3
print("The sum of the 3 integers entered is {}".format(ans))
http://www.daniweb.com/software-development/python/threads/20774/starting-python/19#post2091746
For me Eclipse is woefully sluggish and bloated, since it is written in Java.
Python comes in two major versions and it is nice to be able to run both versions from the same IDE.
To get more information on par you can do this:
# Importing support.py module
import support
support.print_func("Zara")
# to get more insight ...
import inspect
print(inspect.getcallargs(support.print_func, "Zara"))
''' result ...
Hello : Zara
{'par': 'Zara'}
'''
For sheer ease of use the HP Chromebook 11 is handy.
Module math also has:
math.degrees(x) converts angle x from radians to degrees.
math.radians(x) converts angle x from degrees to radians.
You can get a good free online book here:
http://www.greenteapress.com/thinkpython/
Hating might be better than whipping.
It seems that Java is being updated just about every time I turn my Pc on. Is it really that full of bugs?
Here you go:
''' wx_colourdb_show1.py
show the colours in wxPython's wx.lib.colourdb
the database has 630 named colors
use wx.lib.scrolledpanel.ScrolledPanel and wx.GridSizer
to show the colours and their names
Python 2.7.5
'''
import wx
import wx.lib.scrolledpanel
# note the goofy english spelling
import wx.lib.colourdb
class MyScrolledPanel(wx.lib.scrolledpanel.ScrolledPanel):
def __init__(self, parent):
# make the scrolled panel larger than its parent
wx.lib.scrolledpanel.ScrolledPanel.__init__(self, parent, wx.ID_ANY,
size=(600, 450), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
# scroll bars won't appear until required
# default is SetupScrolling(scroll_x=True, scroll_y=True)
self.SetupScrolling()
self.SetBackgroundColour("white")
wx.lib.colourdb.updateColourDB()
# create a list of all the colours in the colour data base
#colours = wx.lib.colourdb.getColourList()
colours = wx.lib.colourdb.getColourInfoList()
# main sizer
vsizer = wx.BoxSizer(wx.VERTICAL)
# wx.GridSizer(rows, cols, vgap, hgap)
gsizer = wx.GridSizer(len(colours), 3, 2, 2)
n = 1
for line in colours:
#print line, # eg. line = ('SNOW', 255, 250, 250)
hexstr = "#%02X%02X%02X" % tuple(line[1:])
s = "%3d %s" % (n, line[0])
t = wx.StaticText(self, wx.ID_ANY, s)
gsizer.Add(t, 0, wx.ALL, border=2)
t = wx.StaticText(self, wx.ID_ANY, hexstr)
gsizer.Add(t, 0, wx.ALL, border=2)
p = wx.Panel(self, wx.ID_ANY)
p.SetBackgroundColour(hexstr)
gsizer.Add(p, 0, wx.ALL|wx.EXPAND, border=2)
n += 1
# now add the whole thing to the main sizer and set it
vsizer.Add(gsizer, 0, wx.ALL|wx.EXPAND, 10)
self.SetSizer(vsizer)
app = wx.App(0)
# create a frame, no parent, default ID, title, size
caption = "all the colours in wx.lib.colourdb"
frame = wx.Frame(None, wx.ID_ANY, caption, size=(600, 450))
MyScrolledPanel(frame)
frame.Show(True)
app.MainLoop()
The news just reported that the Porsche these dummkopfs were driving went over 100 miles/hour in a residential area.
There ar three basic ways to load and display an image with Tkinter:
1) from an image file you have, GIF is native any other file format needs PIL
see tk example in:
http://www.daniweb.com/software-development/python/threads/191210/python-gui-programming#post866067
2) from a base64 encoded image string
pick an example from:
http://www.daniweb.com/software-development/python/code/440446/python2python3-base64-encoded-image
3) from a web page on the internet
example:
http://www.daniweb.com/software-development/python/code/467528/show-internet-image-with-tkinter
You seem to mix those thing up. Stick with one way or the other.
The first line in your function iscount=0
so that is what will happen each time you call the function.
If you use it as an argument, then it is only used when the function is defined, as a default value.
A temporary test print is your friend!
Looks like method getenv(self, tag_str) is missing in the code.
This should work:
def is_string_in_list(mystring, mylist):
for c in mystring:
if c not in mylist:
return False
return True
# short test
mylist = ['a', 'b', 'c']
mystring = 'acb'
print(is_string_in_list(mystring, mylist)) # True
mystring = 'afc'
print(is_string_in_list(mystring, mylist)) # False
I take my iPad with me on the train, but don't commute during typical rush hour.
All those people trying to cover up their wrinkles. I would start sellling cosmetics!
You have to consider that a good chunk of the $634 million contract price goes back to the polititians that made it possible that you got the contract. Not sure what the going cut in Washington is these days.
Looks like your teacher wants a more complex input in function main() like this:
# endless loop with exit condition
while True:
print("Enter tution rate, current year, target year")
print("in the form nnnnn.nn xxxx yyyy")
data = raw_input("? ")
current, thisYear, targetYear = data.split()
current = float(current)
thisYear = int(thisYear)
targetYear = int(targetYear)
# exit condition
if current==0 or thisYear==0 or targetYear==0:
break
# now call your function and get result
#newTuition = tuition(current, thisYear, targetYear)
This basic class example should send you on your Python way:
class Rectangle:
# class constructor
# supply it with initial length and width values
# self refers to the instance
def __init__(self, length, width):
self.width = width
self.length = length
def setLength(self, length):
self.length = length
def show(self):
print("rectangle has length = {}".format(self.length))
print("rectangle has width = {}".format(self.width))
length = 10
width = 5
# create a class instance
rect = Rectangle(length, width)
# show initial setting
rect.show()
''' result >>
rectangle has length = 10
rectangle has width = 5
'''
print('-'*40) # a line of dashes
# now set length to another value
rect.setLength(17)
# show new setting
rect.show()
''' result >>
rectangle has length = 17
rectangle has width = 5
'''
Another video series:
http://www.youtube.com/user/ryanmshea
or:
http://www.youtube.com/playlist?list=PLEA1FEF17E1E5C0DA
Since you are already using Python3, This would simplify it somewhat:
def get_int(prompt="Enter an integer: "):
"""this function will loop until an integer is entered"""
while True:
try:
# return breaks out of the endless while loop
return int(input(prompt))
except ValueError:
print("Try again, value entered was not an integer.")
width = get_int("Please enter the width of your garden in meters ")
length = get_int("Please enter the length of your garden in meters ")
# test
print(width, length)
I read somewhere that Google gets 15 thousand job applications a week. So good luck!
Syria was a French colony for 20 years and the occupation was brutal. Strange that these are the only folks who want to join us in bombing the place.
There are a lot more Java jobs since it takes more person hours to develop programs with Java.
As I understand it, most apps are written with Java. However, there is a lot of garbage out there.
So this is where Samsung gets all their good ideas.
To me Python has always been the quick tool to develop ideas. A bloated cumbersome IDE does not help.
Do not use str for a string variable name
However, if you want to use the error handler, things are a lot simpler and an integer wil be changed to a float too:
while True:
s = raw_input("Enter a float: ")
try:
n = float(s)
break
except ValueError:
pass
print(n)
If the user enters an integer, your program should be smart enough to use it as a float.
I also understood you didn't want to use "try except" error handling.
Quoting:
... but how it will be done without using "try and exception"
Moral:
"Don't assume if a program does not work, that it is fault of the computer or the language."
No need to do that.
Thanks for the info, I have to look into Pillow replacing PIL for Python33.
Why not, as long as they don't ask you wear snowshoes.
The Python3 str.format() method has been backported to Python 2.6.
See
http://docs.python.org/2.6/library/stdtypes.html
http://docs.python.org/2.6/whatsnew/2.6.html
and
PEP 3101
Even with Python33 you can still use the % specifier:
import sys
for key in sys.modules.keys():
print("hello from %s" % key)
Convert the json string object to a Python dictionary and look at the dictionary keys.
Not sure if QMainWindow accepts absolute layout?
Holy smokes woooee, this person has been a busy little beaver.
All this because he/she confuses thousands with hundreths of a second.
Look at something like
PIL.pth
the PIL package directory and it's__init__.py
file
"Dive Into Python" Mark Pilgrim's Free online book, novice to pro, is updated constantly, and has been rewritten for Python3
http://getpython3.com/diveintopython3/
check appendix A for Py2-to-Py3 differences!
Also check:
http://www.swaroopch.com/notes/Python
Google Python video series:
http://code.google.com/edu/languages/index.html#_python_understanding
Slate is right, a little test print within the function allows you to follow what is going on:
def f(x, y):
print(x, y) # test print to check progress
if y == 0:
return x
else:
return f(y, x%y)
print(f(240, 150))
Or:
num = 0
for i in range(0,10,1):
if (i%2 == i%3):
num = num + 1
print(i%2, i%3, num) # test print to check progress
print(num)
Later you can comment out the test print when done.
One more stone turned:
import collections
import random
# values are integers
ddict = collections.defaultdict(int)
for k in range(100):
n = random.randint(0, 10)
ddict[n] += 1
print(ddict[3])
Python 2.7.3 has all the features of Python2 and also allows you to bring in features of Python3. Python3 has a lot of changes when it comes to byte strings that can bite (no pun intended) a beginner trying to use older code examples.
I would stick with a list of tuples and module pickle to save/dump and load the container object. Use a list of lists if you want to edit the contents.
Then simply do something like this:
mylist = [0x123D, 0xFFFF, 0x844F, 0x33E9, 0xFFFF, 0xFFFF, 0xFFFF]
newlist = (mylist[:mylist.index(0xFFFF, 2)])[::-1]
Maybe this:
mylist = [0x123D, 0x844F, 0x33E9, 0xFFFF, 0xFFFF, 0xFFFF]
newlist = (mylist[:mylist.index(0xFFFF)])[::-1]