Go to advanced search

by mattrix
Wed Nov 11, 2015 8:33 pm
Forum: Python
Topic: get access to a class object from another class
Replies: 11
Views: 4112

Re: get access to a class object from another class

I was just going off the code you provided.
Unsure what Master is, but I assume a Tkinter class?

It may be best to paste in your whole code if you need further help.
by mattrix
Tue Nov 10, 2015 7:58 pm
Forum: Python
Topic: get access to a class object from another class
Replies: 11
Views: 4112

Re: get access to a class object from another class

Just do the same as what you are doing with "master" class _Profilwahl: def __init__(self, master, startmenue): ............... self.master = master self.startmenue = startmenue def copy(self): self.startmenue.Listbox_1.value = self.Listbox_1.value startmenue = _Startmenue(master) profilwahl = _Prof...
by mattrix
Mon Nov 09, 2015 11:30 pm
Forum: Python
Topic: running a while loop and other lines of code
Replies: 5
Views: 1080

Re: running a while loop and other lines of code

import time import threading def keepflashing(pin): while flashon: GPIO.output(pin, True) time.sleep(0.23) GPIO.output(pin, False) time.sleep(0.23) print "Done" flashon = True flash_thread = threading.Thread(target=keepflashing, args=(18,)) flash_thread.start() print('The LED is flashing.') time.sl...
by mattrix
Mon Nov 09, 2015 10:00 pm
Forum: Python
Topic: get access to a class object from another class
Replies: 11
Views: 4112

Re: get access to a class object from another class

If you create an instance of Class2, you can pass this to Class1. class Class1: def __init__(self, class2): self.class2 = class2 def test(self): print self.class2.myname self.class2.saySomething("HELLO") class Class2: def __init__(self): self.myname = "Class2" def saySomething(self, text): print tex...
by mattrix
Fri Nov 06, 2015 2:04 am
Forum: Python
Topic: Is my code now "error proofed"...
Replies: 3
Views: 791

Re: Is my code now "error proofed"...

Correct, but that error would have been caught inside the 2nd try except block. Hence the first try except block being redundant :) You could change the 2nd block to only catch only SQL errors and that way the delimiter error would pass out to the 1st try except block. It's quite simple code, so pro...
by mattrix
Thu Nov 05, 2015 8:29 pm
Forum: Python
Topic: Is my code now "error proofed"...
Replies: 3
Views: 791

Re: Is my code now "error proofed"...

Firstly, on the outer except - you only have 2x lines that you are 'catching' delimited_data = rcv.strip().split(',') print(delimited_data) Neither of these will ever error unless rcv was not a string which would mean an error before these lines. split(',') will simply return an empty array if it do...
by mattrix
Wed Oct 21, 2015 8:17 pm
Forum: Python
Topic: run python from website
Replies: 1
Views: 402

Re: run python from website

by mattrix
Mon Oct 19, 2015 11:18 pm
Forum: Python
Topic: Script crashes with no wifi
Replies: 10
Views: 1406

Re: Script crashes with no wifi

import subprocess import smtplib import socket from time import sleep from email.mime.text import MIMEText import datetime # Change to your own account information to = '' gmail_user = '' gmail_password = '' # set a flag sent = false #start a loop while not sent: try: print 'Input detected!' print ...
by mattrix
Mon Oct 19, 2015 11:12 pm
Forum: Python
Topic: Adding Bottle framework in existing python script
Replies: 4
Views: 1340

Re: Adding Bottle framework in existing python script

Well, you haven't even posted the other code - so how are we supposed to help?
by mattrix
Fri Oct 16, 2015 1:25 am
Forum: Python
Topic: Simple web-server
Replies: 4
Views: 1703

Re: Simple web-server

I like bottle.py pip install bottle from bottle import route, run, template @route('/hello/<name>') def index(name): return template('<b>Hello {{name}}</b>!', name=name) run(host='0.0.0.0', port=80) then http://PI_IP/hello/matt from any network PC. You can also use template files from bottle import ...
by mattrix
Fri Oct 16, 2015 1:17 am
Forum: Python
Topic: help needed with skills
Replies: 3
Views: 769

Re: help needed with skills

+1 for the JSON :)

Very nice and easy to get started on.
by mattrix
Fri Oct 16, 2015 1:10 am
Forum: Python
Topic: Adding Bottle framework in existing python script
Replies: 4
Views: 1340

Re: Adding Bottle framework in existing python script

Try this...

Code: Select all

from bottle import route, run

@route('/hello')
def hello():
    return "Hello World!"

run(host='0.0.0.0', port=8080)
0.0.0.0 will let you call it from any PC on your network.

Have you installed bottle?

Code: Select all

pip install bottle
by mattrix
Wed Oct 14, 2015 3:39 am
Forum: Python
Topic: RF Communication with Python (Send Only)
Replies: 11
Views: 2666

Re: RF Communication with Python (Send Only)

Why not use the C program from here (linked above from other poster) http://www.homautomation.org/2014/03/02/433mhtz-rf-communication-between-arduino-and-raspberry-pi-arduino-as-receiver/ The program takes an argument for the code to send, so just use Python to call the program with the code you wan...
by mattrix
Mon Oct 12, 2015 8:25 pm
Forum: Python
Topic: Help with Login
Replies: 11
Views: 1703

Re: Help with Login

sorry, I only had Python2.7 on my work PC, so wrote the code in Python2 and tested and then "roughly" converted to Python3 but missed the unicode hashlib line.

Good to hear it's working
by mattrix
Tue Oct 06, 2015 10:05 pm
Forum: Python
Topic: Help with Login
Replies: 11
Views: 1703

Re: Help with Login

I would do it like this import time import sys import os import hashlib .. .. password_file = '/home/pi/.infinity/programs/data/cb_usernames.txt' ... .. if register.lower() == "y": #you can do it like this instead of checking for y and Y newusername = input ("What do you want your username to be?") ...
by mattrix
Tue Sep 22, 2015 11:12 pm
Forum: Python
Topic: Difference between Python 2 and Python 3
Replies: 11
Views: 2334

Re: Difference between Python 2 and Python 3

print "hello world"
vs
print("hello world")

That's it :)
(Not really)
by mattrix
Tue Sep 15, 2015 6:26 am
Forum: Gaming
Topic: recalboxOS - emulation platform for RPi and RPi2
Replies: 494
Views: 154642

Re: recalboxOS - emulation platform for RPi and RPi2

I can also confirm setting:
controllers.ps3.driver=gasia
works great with my Gasia controllers :)

Only small annoyance is that both controllers show player 1 led :)
by mattrix
Tue Sep 15, 2015 3:01 am
Forum: Gaming
Topic: recalboxOS - emulation platform for RPi and RPi2
Replies: 494
Views: 154642

Re: recalboxOS - emulation platform for RPi and RPi2

Idea for Recalbox Have you ever considered making KODI into a separate NOOBS package? So, clicking KODI would simply reboot into that partion. This way, it could be optional but most importantly it would be "vanilla" media center and easily upgradeable etc. You also then wouldn't need to worry abou...
by mattrix
Mon Sep 14, 2015 11:32 pm
Forum: Gaming
Topic: recalboxOS - emulation platform for RPi and RPi2
Replies: 494
Views: 154642

Re: recalboxOS - emulation platform for RPi and RPi2

Love the update :)

Dual boot OSMC & Recalbox

I have made a blog post about how to nicely dual-boot between Recalbox and OSMC

http://www.matthuisman.nz/2015/09/dual- ... -osmc.html
by mattrix
Tue Sep 08, 2015 3:25 am
Forum: Interfacing (DSI, CSI, I2C, etc.)
Topic: Safest way to wire up optocoupled relay module?
Replies: 4
Views: 818

Re: Safest way to wire up optocoupled relay module?

Yes, it works either way fine. LED lights up correctly etc. I am using this one http://pishop.nz/RPI-RELAY-1.html Resistor (R1) is labeled "821" (I think) and measures 0.808k so, 800 ohms I think I might use the 2nd method. It seems safer. If the wire somehow came lose and hit earth, it wouldn't act...
by mattrix
Tue Sep 08, 2015 1:23 am
Forum: Interfacing (DSI, CSI, I2C, etc.)
Topic: Safest way to wire up optocoupled relay module?
Replies: 4
Views: 818

Safest way to wire up optocoupled relay module?

Hi all, I am wiring up a small relay module board to the Raspberry Pi. This board is used to open/close my garage door - so I don't want any chance of the relay triggering without being told (eg. on boot). Here is a circuit diagram of the relay module http://www.wavetech.co.nz/images/cache/rpi-relay...
by mattrix
Thu Sep 03, 2015 1:09 am
Forum: Python
Topic: Python from PHP Button
Replies: 14
Views: 2745

Re: Python from PHP Button

That's how I would do it :)

I was going to say, just run bottle.py on port 80, but you obviously have another site running already.

I use proxy-pass a lot for services that run on different ports.
by mattrix
Thu Jul 23, 2015 2:53 am
Forum: Python
Topic: My First Attempt at RPi/Python - Constructive comments plse.
Replies: 2
Views: 586

Re: My First Attempt at RPi/Python - Constructive comments p

You repeat alot. You should consider using a dictionary to store the values of items that change. Something like this: (untestest) import time import RPi.GPIO as GPIO import pygame pygame.mixer.init(48000, -16, 1, 1024) SWITCHES = { 'sleep' : {'pin': 4, 'name': 'Sleep Switch', 'value', None}, 'away'...
by mattrix
Fri Jun 26, 2015 1:48 am
Forum: Python
Topic: script wont load at boot, but will run manually just fine
Replies: 8
Views: 3509

Re: script wont load at boot, but will run manually just fin

You say you are putting the python command into the "/etc/init.d/rc.local" file? This is not correct. No need to modify /etc/init.d/rc.local at all. You should put your line in the /etc/rc.local file before the "exit 0" line sudo nano /etc/rc.local Also make sure /etc/rc.local is executable sudo chm...
by mattrix
Thu Jun 25, 2015 8:55 pm
Forum: Python
Topic: Proofread my Coding?
Replies: 9
Views: 963

Re: Proofread my Coding?

Can I ask you what each part of the code does? I'm having trouble figuring out how the computer knows if the pairing is correct or incorrect. At the top of the script, we define a simple Python dictionary. PIN_PAIRS = { 18:17, 23:22, } A dictionary has a KEY and a VALUE (separated by a colon) I am ...

Go to advanced search