This snippets contains a python program to find a shortest solution to the problem of the farmer who whishes to cross a river. The boat can only contain two things, including the rower. The farmer comes with a wolf, a duck and a bag of corn, and he can't leave the duck alone with one of the other items because the wolf would eat the duck, or the duck would eat the corn. The program shows how to use a `collections.OrderedDict` to implement a stack without repetitions. This is used to traverse a tree of states. These states, encoded as …

Member Avatar
Member Avatar
+0 forum 5

Hi I got this error when I ran my scrip? import vidcap,time ImportError: No module named vidcap Where can I download the module?

Member Avatar
Member Avatar
+0 forum 2

So I am trying to make this code run in a constant loop. Any ideas how I would do this? As I said before I am trying to self teach myself Python and so far I have been successful. import os import datetime import time print('What would you like to do?') answer = raw_input() today = datetime.date.today() if answer == 'shutdown': print('This works') elif answer == 'restart': print('This also does work') elif answer == 'restart': print('This also works fine') elif answer == 'date': print today elif answer == 'time': print (time.strftime("%H:%M:%S")) else: print('Did not recognize that request, sorry.')

Member Avatar
Member Avatar
+0 forum 7

A strange phenomenon! What is this number 8! We are in the 2.7 version of Python. **MY CODE ** x = raw_input("write a list! utilisation of raw_input ") y = input("write a list! utilisation of input ") print x, "resultat of rawinputation" print y, "resultat of inputation" **My input and the Terminal ** write a list! utilisation of raw_input [x * 3 for x in range(2, 10, 2)] write a list! utilisation of input [x * 3 for x in range(2, 10, 2)] 8 resultat of rawinputation [6, 12, 18, 24] resultat of inputation **The lesson: ** a) an important …

Member Avatar
Member Avatar
+0 forum 12

Hello, this is my first post in this forum. I recently decided to try my hand at programming with python. I'm completely new to programming so I thought I should try some simple projects to reinforce what I've learned so far. I saw a post from 3 years ago on this forum about a unit converter that has to work with inches, feet, miles, millimeters, centimeters, meters, and kilometers, and thought it would be a good project to try. So far I've only written enough script to convert from inches to any of the units mentioned above. I've got the …

Member Avatar
Member Avatar
+0 forum 7

I am trying to use web2py to build an app. I have a simple print function that a user submits a key word . The string or int key word is directed to an sqlite db to retrieve a row and output the data. I need to know 1. how to use the print on html. 2. How to split the string...so far i did the list:string Here is my code: def first(): form = SQLFORM.factory(Field('visitor_name', label = 'Please Type Your keyword here!', requires= [IS_NOT_EMPTY(), IS_LOWER(),'list:string'])) form.element('input[type=submit]')['_onclick'] = "return \ confirm('Are you sure you want to submit:');" if form.process().accepted: session.visitor_name …

Member Avatar
+0 forum 0

Hi Friends, (i) I'm very new to python.so i wanna know which version of python is suitable for me.I have [I][B]python 2[/B][/I] and [I][B]python 3[/B][/I] in my choices..which one is best for me??? (ii)Also give me the list of GUI toolkits for respective versions.. (iii)which version has the best library for web development? Note: I will be mostly working on GUI & Web development. Thanks in advance...

Member Avatar
Member Avatar
+0 forum 7

Trying use radio buttons to select which host I'm referring to since ultimately there will only be two and they are fixed addresses. This is the error: File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1410, in call return self.func(*args) File "Untitled 2.py", line 63, in command=lambda: callback_power_off(off, host)) File "Untitled 2.py", line 28, in callback_power_off connection.connect((host, port)) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) TypeError: coercing to Unicode: need string or buffer, instance found from Tkinter import * from socket import * port = 7142 on = '02 00 00 00 00' off = '02 01 00 00 00' def callback_power_on(data, host): if …

Member Avatar
Member Avatar
+0 forum 3

hi guys !!! i want to make an web browser in python , as my college project . what i'm looking for is guidance , on how to make it and which module's shall i use . currently i'm planning to use webkit and gtk+ to obtain my goal. secondly how can i ensure that all websites will work properly ??? means how will i parse html and java script in the browser ? any suggestions and comments are welcomed !!

Member Avatar
Member Avatar
+0 forum 4

This, of course, is not my code. It's from my object oriented programming course book. During class I ran the program and it worked a good 75% of the time without making any changes. For some reason, when I run it at home(either on python 2 or python 3) it won't work at all. I get error NameError: name 'Monitor' is not defined. Why is it doing that? # Program: ShapeHandler.py # Authors: Michael H. Goldwasser # David Letscher # # This example is discussed in Chapter 15 of the book # Object-Oriented Programming in Python # from cs1graphics import …

Member Avatar
Member Avatar
+0 forum 3

If you have a smaller image, you can include it in your program as a base64 encoded string. This way you don't have to worry about an image file to go with your code. In your program you can then decode it back to the familiar bytes of an image and use it. This code snippet should work with Python2 and Python3 versions.

Member Avatar
Member Avatar
+5 forum 5

We can run Python2 script in most simple cases if we just use the 2to3.py script found in recent Python versions: F:\Python27\Tools\Scripts>copy \test\output_window_tk.py \test\output_window_tk2.py 1 tiedosto(a) on kopioitu. F:\Python27\Tools\Scripts>2to3.py -w \test\output_window_tk.py RefactoringTool: Skipping implicit fixer: buffer RefactoringTool: Skipping implicit fixer: idioms RefactoringTool: Skipping implicit fixer: set_literal RefactoringTool: Skipping implicit fixer: ws_comma RefactoringTool: Refactored \test\output_window_tk.py --- \test\output_window_tk.py (original) +++ \test\output_window_tk.py (refactored) @@ -1,5 +1,5 @@ -from ScrolledText import ScrolledText -from Tkinter import BOTH, YES, END +from tkinter.scrolledtext import ScrolledText +from tkinter import BOTH, YES, END fn = 'f:/Python27/setuptools-wininst.log' mywin = ScrolledText() RefactoringTool: Files that were modified: RefactoringTool: \test\output_window_tk.py Here we backed …

Member Avatar
+0 forum 0

Is there an easy way to modify the contents of a zip file inside the archive, without unpacking everything to a temp directory, making the change, then packing it all up again? I've got a whole bunch of zip files, each one with a bunch of plain text files (html, xml, txt) in a fussy directory structure. My script needs to open up the zip files, and make occasional changes to the files within. Currently the relevant part of my code goes like: [CODE] for root, dirs, files in os.walk(maindir): for currentfile in files: currentzip = zipfile.ZipFile(os.path.join(root, currentfile), mode='r') innernames …

Member Avatar
Member Avatar
+0 forum 2

I have create in MySQdb a DB with a table named example,in this table i want to save a name, this name is in Greek language.My problem is thw follown when i try to save the name instantly without use textctrl, its ok but when i use textctrl i take error.Look the code: Can anyone hel me please i have try encoding in utf-8,decoding in utf-8, to unicode but nothing. [CODE] import os import math import random import wx import MySQLdb import sys APP_SIZE_X = 500 APP_SIZE_Y = 300 # -*- coding: utf-8 -*- class MyFrame(wx.Frame): def __init__(self, parent, id, …

Member Avatar
Member Avatar
+0 forum 2

I have a battleship python assignment due in an hour and I can't figure out where the error is in this code. It seems like when player 2 plays sometimes the coordinates saved in Board.remaining_ships can't be deleted because they aren't there. Please please please help Here is the error: Traceback (most recent call last): File "/Applications/WingIDE.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 256, in <module> File "/Applications/WingIDE.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 40, in bullet_positioning ValueError: list.remove(x): x not in list Code: [CODE]import random class Ships(object): def __init__(self, ship_num): '''ship_num is a list of int containing the numbers of ships of size 2, 3, 4 and 5 squares. …

Member Avatar
Member Avatar
+0 forum 1

i using this code for making a page but the images are not showne in web browser win i deploy the script please help..... [CODE] def get(self): self.response.out.write(""" <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>my page</title> <link href="stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>my page</h1> """) f_path=os.path.join (os.path.dirname (__file__),'\image') self.response.out.write (" <div><img src=\"" + os.path.join(f_path,"media.jpg")+'\"'+ """ align="absmiddle" vspace="1" width="144" height="192" hspace="1" /></div>""") self.response.out.write (" <div><img src=\"" + os.path.join(f_path,"main.jpg")+'\"'+ """ align="absmiddle" vspace="1" width="72" height="96" hspace="1" />"""+ " <img src=\"" + os.path.join(f_path,"main.jpg")+'\"'+ """ align="absmiddle" width="72" height="96" vspace="1" hspace="1" /></div> """) self.response.out.write ("""</body> </html>""") [/CODE]

Member Avatar
Member Avatar
+0 forum 1

Hello, Friends, I am new to python, currently I have a requirement to use python to create a mapreduce job in HADOOP... I searched every where but couldn't get any lead. 1) First I need read a KEY, VALUE pair from the Hadoop sequential file. 2) Secondly, need to uncompress the Value read from the sequential file Please help me..... Is there any builtin class in hadoop that can be used in python to read the sequential file?

Member Avatar
Member Avatar
+0 forum 4

[B]I am trying to return True or False by comparing dimension size(width and heights) of two pictures. so i came up with[/B]import media f = media.choose_file() pic = media.load_picture(f) g = media.choose_file() pic1 = media.load_picture(g) x = pic.get_width() * pic.get_height() y = pic1.get_width() * pic1.get_height() [B]but i have no idea return these valuse to true and false(bool). Also, i have another thing to solve, Return a new 20 pixel by 20 pixel Picture that has a white background, a black 16 by 16 oval at position (0, 0), and a black letter C (uppercase) at position (6, 3). For this …

Member Avatar
Member Avatar
+0 forum 5

I'm using python IDLE v. 2.7.2 and I get the same error report with my program. [CODE]>>> def menu(list, question): for entry in list: print 1 + list.index(entry), print ") " + entry return input(question) - 1 [B]items[/B] = ["Cup","Vase","Table","Lamp","Bowl","Door"] keylocation = 3 keyfound = 0 loop = 1 print "Welcome to The Great Text Adventure!" print "One day you wake up, in a room, locked in by yourself." print "Could there be a key? print "In the room you see." print len (items), "things:" for x in items: print x print "" while loop == 1 choice = menu(items, …

Member Avatar
Member Avatar
+0 forum 11

I am trying to convert a 2d image to 3d one in python. please introduse me some good source or if there is an open source program. Thanks alot.

Member Avatar
Member Avatar
+0 forum 10

i have been working on this course work i got my hands on to learn python, and i have just been working on an exercise, i was wondering if i perhaps cheated though? The exercise says the following; write a function that takes a list of real numbers and returns both the maximum and the minimum values. Put the function in a module file with some simple test code. Make it work for positive and negative floating point numbers. i wrote the following as a solution; [CODE] def MinMax(numbers): ''' This is a function to sort a list of real …

Member Avatar
Member Avatar
+0 forum 4

Hi all i am college student and making a project related to file compression in python. I want to creat a listCntl with image and text that will look like image that i attached wih this post. plese help me how will i implement this in wx python.

Member Avatar
+0 forum 0

What is wrong with this code? [CODE]import time import sys print """Welcome to the age finder. This program takes some input (they will be the years) and then adds it to 4 ages. For example, if you give the ages 10, 11, 12 and 13 it will return the age added to your first input. """ # These are the years to add. print "Enter the number of years to be added:" yearstoadd = int(sys.stdin.readline()) # These are the ages to add. print "Enter the first age:" num1 = int(sys.stdin.readline()) if num1 > 100: print "Sorry, this is a very …

Member Avatar
Member Avatar
+0 forum 9

how i can set a header and footer when printing a QTextDocument in pyqt4 ?

Member Avatar
+0 forum 0

hello everyone , i need to make a borders for my printing report and i need a function that move my logo into middle of my report at first line , how i can do these things in Qt4 ?? i write thia code using PyQt4 [CODE]QtCore.QObject.connect(self.pushButton_5,QtCore.SIGNAL(_fromUtf8("clicked()")),self.Delete) def Delete(self): self.printer = QtGui.QPrinter() self.printer.setPageSize(self.printer.A4) self.text = QtGui.QTextEdit() self.cursor = QtGui.QTextCursor() self.cursor = self.text.textCursor() self.image = QtGui.QTextImageFormat() self.image.setName("leaf.jpg") self.cursor.insertImage(self.image) pdialog = QtGui.QPrintPreviewDialog(self.printer) pdialog.paintRequested.connect(self.text.print_) pdialog.exec_()[/CODE]

Member Avatar
Member Avatar
+0 forum 1

I recently received an assignment in class and I need help really bad. The idea behind this assignment is to create a Network Backup Routine that that has a selection menu (New Backup Item, Remove Backup Item, Exit), I have been trying to create this program but with a sub menu to (New Backup Item and Remove Backup Item) that allows me to chose from one of the three priorities(High Priority, Medium Priority, Low Priority and an option to Return To Main Menu). After building the menu and sub menu I need to a loop that will count the total …

Member Avatar
Member Avatar
+0 forum 4

Hello everyone, :) I have exercise for class that I can't complete, I don't understand why my loops aren't working The question--- Write code that will print a multiplication table for 10 positive integers across the columns and 10 positive integers down the rows. Prompt the user for the starting values for both the columns and the rows. My attempt--- [CODE]row = int(raw_input("Enter the first row number: " )) col = int(raw_input("Enter the frist column number: ")) lastRow = row + 10 lastCol = col + 10 while (row < lastRow): print "%4d" % (col * row) while(col < lastCol): …

Member Avatar
Member Avatar
+0 forum 1

I am in desperate need of help with a python 2.7 project I am working on. I am really struggling in the class and they messed up my tutoring appointment for tonight so I have no one to help me. I am doing a project that reads a .csv file and creates multiple .html files from the information. We are also given an html template to use. 1. The steps are to read the file and create a list form each row. 2. Each row creates an .html file. 3. Each value in the row is written in a new …

Member Avatar
Member Avatar
+0 forum 3

im trying to write a code that i can input a,b,c and the code will run it in the quadratic formula and give me the answer but i keep getting a error problem import math from math import sqrt print print ("Welcome to the Quadratic Program") print ("--------------------------------") print a=input("Enter a: ") b=input("Enter b: ") c=input("Enter c: ") print print answer=[b+(math.sqrt((b*b)-(4*a*c)))]/(2*a) if answer<0: print ("negative") print answer

Member Avatar
Member Avatar
+0 forum 2

I would like to know how to use a list contain with file names returned from a function to search a directory based on that list then copy the matching files to another directory. Following is what I would like to accomplish in logical order. 1. Existing Function getPromptList() return PromptList which contain a list of files. 2. Create a Function copyLiveToPrompt which taking the PromptList against the Source Directory and find files match the PromptList then copy them to the Destination Directory. New to Python and will post some code. Please help... Thanks.

Member Avatar
Member Avatar
+0 forum 8

The End.