Is it possible to store a certain function as a variable? If not, is it okay to make a class, and define a function. Store the class as the variable and invoke that function?

Member Avatar
Member Avatar
+1 forum 7

hi there i have some python coding which i need to convert to java can ne1 help me please email me back if you can help then i will show you the coding much appriciated

Member Avatar
Member Avatar
+0 forum 8

[B]Hi all.. I need to do a condition check in a script. The same condition check needs to be repeated in another script. So, I am looking for a way, where i can set, say a flag in the first script ,upon meeting the condition, and be able to access that flag in another script, instead of repeating the check all over again. Hope I am clear in explaining what I want to do. Can anyone pls give me suggestions? [/B]

Member Avatar
Member Avatar
+0 forum 13

Hello fellow python lovers of daniweb.com. This isn't as much a question as much as the fact that I want to see how different people would go about using python to inject an SQl database. I made a script were you can access the ip and run a command. NOTE:Obviously I didn't give an actual database. Who am I kidding you guys aren't stupid. Here's my injection script import MySQLdb db = MySQLdb.connect(host="localhost", # your host, usually localhost user="USER", # your username passwd="PWD", # your password db="MySQLdb") # name of the data base # you must create a Cursor object. …

Member Avatar
Member Avatar
+0 forum 4

Fellow Python developers, Python has a sorted() or sort() function to implement ascending or descending order programs,but supposing if i want to develop a ascending order program that takes user input and ascends or descends them,how should I go about? For Example: Lets Say i want to convert this C program to Python? # include <iostream.h> # include <conio.h> void main() { int a[10],i,j,n,temp; clrscr(); cout<<"\nEnter n nos: "; cin>>n; cout<<"\nEnter the numbers: "; for(i=0;i<n;i++) cin>>a[i]; for(i=0;i<n;i++) for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } for(i=0;i<n;i++) cout<<a[i]<<endl; getch(); } This is an ascending order program in C. Thanks in …

Member Avatar
Member Avatar
+0 forum 4

Hi i have been spending the last few days deciding on an IDE that would let me program in Java, C++ and python and notepad++ looked pretty good. The only issue is i cant work out how to make the program run once i have made it. I looked in google and i couldn't find any tutorials to set it for python but if anyone could help that would be greatly appreciated. Thanks!

Member Avatar
Member Avatar
+1 forum 8

Hi, i was working on a code for a vending machine and i do consider myself to be a beginner, anyway i feel my code is much longer than it needs to be and i want someone to show me a new, shorter way of presenting it. import time print ("Welcome to the Python Vending Machine.") # Asking the user how much money they wish to enter. number_of_10p = int(input("How many 10 pence coins would you like to insert? ")) while number_of_10p < 0: number_of_10p = int(input("Please enter a positive number.")) number_of_20p = int(input("How many 20 pence coins would you …

Member Avatar
Member Avatar
+0 forum 5

Hi, i wasn't sure about the title of my question, hope its okay. Anyway, the program i have is suppose to read a binary file then find for specific bytes like this: bytes1 = bytearray(b'\x41\x64\x6F\x62\x65\x20') filename = "portrait1.dng" with open(filename, "rb") as binaryfile: with open("foundhex.txt", "w") as found: found.write("File that is analysed : " + filename + "\n") found.write("Date of analysis : " + str(today) + "\n") while True: read_file = bytearray(binaryfile.read(1024)) find_bytes1 = read_file.find(bytes1, 0) if fine_bytes1 != -1: with open("foundhex.txt", "a") as found1: found1.write("Found 41646F626520 at : " + str(find_bytes1) + "\n") if not read_file: break basically, it …

Member Avatar
Member Avatar
+0 forum 3

Hello. I got one question, when i want to streamplot this, i got eror: "raise ValueError("The columns of 'y' must be equal")", i can't figure it out. :/ Thank you for your time. this is entire code: import matplotlib.pyplot as plt import numpy as np # discretization of domain x_start, x_end = 0. , 10. y_start , y_end = 0. , 8. i = np.linspace(x_start, x_end, 80) j = np.linspace(y_start, y_end, 50) X,Y = np.meshgrid(i,j) Y[:,:40] += 1 Dx = x_end/(np.size(i)-1) Dy = y_end/(np.size(j)-1) beta = Dx/Dy nx = np.size(i) #number of points on x axis ny = np.size(j) #number …

Member Avatar
Member Avatar
+0 forum 1

Hi all, The continuing quest to master Tkinter has led to this implementation of the dots and boxes game. The rules are well-known: each player gets to create a new line between two dots (single-click near the line you wish to create). If a player creates a box, he gets a point *and* gets to go again. (Two boxes gets two points, but only one extra turn.) The highest score out of 81 boxes wins! Please feel free to mercilessly criticize the UI or the code; I'm looking to improve it and submit to the Code Snippets thread. Thanks, Jeff …

Member Avatar
Member Avatar
-1 forum 5

import tkinter root = tkinter.Tk() root.geometry("200x200") buttons=[i for i in range(10)] def getNext(): #If specific button is pressed, output "YES" for num in buttons: btn=tkinter.Button(root, text=num,command=getNext) btn.pack(side=tkinter.TOP)

Member Avatar
Member Avatar
+0 forum 1

I want to associate a REST API end point to two urls, "manager" and "manager/". So I added two path entries in the urlpatterns with these urls. But it seems something that can be handled with some kind of configuration. Is there such a configuration with django? thanks

Member Avatar
Member Avatar
+0 forum 1

hi. i have a really basic question (really new to python). how do i read an entire binary file? from https://www.devdungeon.com/content/working-binary-data-python , `data = binary_file.read()` is to read the whole file at once. so i have a .dng file to test, which is 16.2mb, and i did: with open("portrait1.dng", "rb") as binary_file: #Read the whole file at once data = binary_file.read() #Return the hexadecimal representation of the binary data, byte instance hexa = binascii.hexlify(data) with open("readprotrait1.raw", "wb") as write_file: write_file.write(hexa) im using a hex editor to see if the data from .dng gets copied to the .raw file but only …

Member Avatar
Member Avatar
+0 forum 2

This is my custom module: [CODE]class Player(object): def __init__(self, name, score = 0): self.name = name self.score = score def __str__(self): rep = self.name + ":\t" + str(self.score) return rep def ask_yes_no(self, question): response = None while response not in ("y", "n"): response = input(question).lower() return response def ask_number(self, question, low, high): response = None while response not in range (low, high): response = int(input(question)) return response[/CODE] The program: [CODE]import games, random print "Welcome to the world's simplest game!\n" again = None while again != "n": players = [] num = games.ask_number(question = "How many players? (2-5): ", low = …

Member Avatar
Member Avatar
+0 forum 10

Hi. I have a .raw file and I want to display it as hex. why? because i want to try and replicate what 010 Editor can do which is read any sort of file and display in whatever format user desires (plus it can be used to edit and stuff) but I'm focusing on .raw files only and to display in hex only. i sort of understand that binascii.hexlify() returns the hexadecimal representation of the binary data (.raw files are binary data right?) but when i do : content = open(fileName, "rb") byte = content.read(1) hexadecimal = binascii.hexlify(byte) self.file_content.setText(hexadecimal) I …

Member Avatar
Member Avatar
+0 forum 8

Have two CSV files containing client records and need to compare the two and then output to a third file those rows where there are differences to the values within the record (row) as well as output those records (rows) on the second file that are not on first file . Example: File 1: KeyField,Name,City, Zip,Location 123,Fred,Chicago,60558,A2 234,Mary,Orlando,12376,4L6 345,George,Pittsburgh,40567, 22 456,Peter,Topeka,00341,234 567,Doc,Birmingham,76543,H86 File 2: KeyField,Name,City,Zip,Location 123,Fred,Chicago,60558,A2 234,Mary,Orlando,12376,4L6 345,George,Boston, 40567,22 456,Peter,Topeka,00341,234 567,Doc,Birmingham,7654,H86 678,Isabel,Guadalajara,87654,M111 The results should create a file containing : 345,George,Boston,40567,22 678,Isabel,Guadalajara,87654,M111 The following code gets me in the neighborhood as a visual check: import os import difflib f=open('original.csv','r') #open …

Member Avatar
Member Avatar
+0 forum 7

Hello all, i need your help regaring this code, which is in python and i need to convert it into mips?? register $s0 holds the base address of list my_data, $s1 holds the length of the list my_data, register $s2 holds the base address of list my_data2 and $s3 holds the length of the list my_data2. def sum_to_x(x): sum = 0 for i in range (x): sum += i return sum my_data = [1, 3, 6, 7] my_data2 = [2, 1, 5] for i in range( len( my_data ) ): my_data[ i ] = sum_to_x( my_data[ i ] ) for …

Member Avatar
Member Avatar
-1 forum 6

If you're in one of those predicaments where `cls.__private` attributes just aren't enough since they can easily be accessed through `inst._cls__private`, and you need something a little more secure, here's a method I've been playing with for a while that fills that gap. Note that this uses `__slots__`, more info on this below the code. def private(): # no outside access class A(object): __slots__ = ['__private__'] def __init__( inst, val=None ): setprivate( inst, val ) def __repr__( inst ): return '<A %s >' % getprivate( inst ) globals()['A'] = A # add our class to the public namespace dsc = …

Member Avatar
Member Avatar
+0 forum 1

Hi guys have a python software that i want to freeze for distribution. The problem is after freezing it with cx_freeze and i run it, it works fine on my development computer but when i sent it to my testing computer (window XP sp3 32bit) it give me this error Traceback(mostresent call last): File "C:Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line27, in <module? File "timeTracker.py", line 555, in <module> File "timeTracker.py", line 381, in __init__ File "timeTracker.py", line 427, in runTimeThread File "timeTracker.py", line 494, in __init__ File "timeTracker.py", line 118, in __init__ File "C:Python27\lib\site-packages\pyttsx1.1-py2.7.egg\pyttsx\__init__.py", line 39, in init File "C:Python27\lib\site-packages\pyttsx1.1-py2.7.egg\pyttsx\engine.py", line 45, in __init__ …

Member Avatar
Member Avatar
+0 forum 9

How to write pseudocode in python

Member Avatar
Member Avatar
+0 forum 3

Guys, I am trying to change the background color of my window in WxPython. Here is what I got: Why doesn't it work? [CODE]import wx class my_window(wx.Frame): def __int__(self, parent, id): wx.Frame.__int__(self,parent,id,'My Window', size=(300,200)) self.Colours() def Colours(self): self.pnl1.SetBackgroundColour(wx.BLACK) if __name__ == "__main__": app=wx.PySimpleApp() frame=my_window(parent=None,id=-1) frame.Show() app.MainLoop()[/CODE]

Member Avatar
Member Avatar
+0 forum 5

Hello, everybody. I was wondering if anybody could help me with something. I don't know if I'm taking things too fast but, I was wondering if somebody could help with this program I am making. I'm currently writing a "fake" bank script. Basically you start with a set amount of money, and you can deposit it, withdraw it, and check your balance. However, when I make the deposit and then check my balance, I shows up as the balance being 0, instead of what I had deposited... Could somebody help me out?? Here's the code: Bank.pyw: [CODE]#THIS PART IS NOT …

Member Avatar
Member Avatar
-1 forum 13

I need some help why can't I create an instance of the child class without an error ? class tv(): def _init__(self,color,screen,frame): self.color=color self.screen = screen self.frame = frame def DesOfTV(self): info = "The TV has a"+self.color+"and a"+self.screen+"screen" return info class retroTV(tv): def __init__(self,color,screen,frame): super().__init__(color,screen,frame) oldertV = retroTV("black","tuber","wood")

Member Avatar
Member Avatar
+0 forum 1

Hello! Can you give me an example of Button widget in Kivy language? I can creat the button but don't know how to use it's callback. I mean how can i set a command for the Button in Kivy?

Member Avatar
Member Avatar
+0 forum 10

Hi, yesterday I threw together a little jumble solver that takes any anagram as an input and returns any real words that can be found using all of the letters of that anagram. Here is the code, it works fine when it comes to determining the answer, but I have a couple of questions. [CODE]# jumble.py import string def anagrams(s): if s == "": return [s] else: ans = [] for an in anagrams(s[1:]): for pos in range(len(an)+1): ans.append(an[:pos]+s[0]+an[pos:]) return ans def dictionary(filename): dict = {} infile = open(filename, "r") for line in infile: word = line.split("\n")[0] dict[word] = 1 …

Member Avatar
Member Avatar
+0 forum 5

so I'm working on a class for a vector which I want to hash like a tuple, and to do so, a vector instance needs acess to it's properties. here's the constructor for the performative properties I'm using, and the vector class: def newProp(): newdict = {} getter = newdict.get setter = newdict.__setitem__ def wrapper(vec,val): if val is None: return vtype = val.__class__ if vtype is str: setter(vec, float(val) ); return if numtype(vtype): setter(vec,val) return property(getter, wrapper) class vector(object): __slots__ = [] X = newProp() Y = newProp() Z = newProp() W = newProp() def __init__(vec,*other): # other is for …

Member Avatar
Member Avatar
+0 forum 11

I have a text file containing the following data. ascon1 201707011 John 77.5 11.5 11.5 11.5 ascon1 201707012 Grld 70.0 11.5 11.5 11.5 ascon1 201707013 Josh 79.5 11.5 11.5 11.5 ascon1 201707014 Jess 67.5 11.5 11.5 11.5 ascon1 201707015 Jack 97.5 11.5 11.5 11.5 I need the data to look like this. ascon1 201707015 Jack 97.5 11.5 11.5 11.5 ascon1 201707013 Josh 79.5 11.5 11.5 11.5 ascon1 201707011 John 77.5 11.5 11.5 11.5 ascon1 201707012 Grld 70.0 11.5 11.5 11.5 ascon1 201707014 Jess 67.5 11.5 11.5 11.5 so here is my code. The above part is working using the inbuilt …

Member Avatar
Member Avatar
+0 forum 10

I am searching for the logical Python logical operator "or"; While C++ is: 1 || 4 (using pipes) I assume Python would simply be "or", as in: 1 or 4 Or something like this: if var1 == "image0.GIF" or "image1.GIF" or "image2.GIF": varValue = 10 Is this syntax for Python "or" correct in my examples? Thank-you in advance. sharky_machine

Member Avatar
Member Avatar
+0 forum 7

I have an automated API with a secure frontend/backend structure where backend object attributes are hidden with frontend proxy classes. basically, when accessing an object from the frontend, you get a proxy object disguised as the backend object with all it's explicitly "public" functionality. what I'm dealing with right now seems to be a design flaw with python's descriptor implementation: Instance.Attr[item] = value what this equates to in Python is: Instance.__class__.Attr.__get__( Instance, Instance.__class__ ).__setitem__( item, value ) the insecurity with this is `__get__` instead of just simply being `__setitem__`, meaning I have to pass a private object into my frontend …

Member Avatar
Member Avatar
+0 forum 14

Hello, I was testing a class in a GUI, and that error message showed up. Please help. Code: [CODE]from Tkinter import * class Application(Frame): def __init__(self, master): super(Application, self).__init__(master) self.grid self.create_widgets() def create_widgest(self): self.bttn1 = Button(self, text = "I do nothing!") self.bttn1.grid() self.bttn2 = Button(self, text = "Me too.") self.bttn2.grid() self.bttn3 = Button(self, text = "Same here..") self.bttn3.grid() root = Tk() root.title("Lazy buttons") root.geometry("200x100") app = Application(root) root.mainloop[/CODE]

Member Avatar
Member Avatar
+0 forum 11

The End.