@dgelessus thanks again, I just deleted the heads line and it ran fine. I’ll be sure to include your reference tips in future posts too.
Craig
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.

Best posts made by craigmrock
-
RE: Syntax error def__init__(self, rare=False)
Latest posts made by craigmrock
-
Calling one function in another function
Trying to store my calculations in one function and call it in my input function to output a total. If level 1 is selected, I want it to find level 1 in the get_sales function and multiply that percentage by the salesAmount variable in the salesPerson function.
def get_sales(s): level1 = 0 if s <= 2500: level1 = s * 0.045 return level1 def salesPerson(): salesNum = input("How many sales persons? ") for num in salesNum: salesName = input("Enter sales person name: ") salesLevel = 0 while salesLevel == 0: try: salesLevel = int(input("Enter sales person level: ")) if salesLevel < 1 or salesLevel > 4: print("error, try again.") salesLevel = int(input("Enter sales person level: ")) if salesLevel == 1: salesLevel = get_sales(salesLevel) except: print("error, try again.") continue hoursWorked = float(input("Enter hours worked: ")) salesAmount = float(input("Enter sales amount: ")) print(salesLevel*salesAmount) salesPerson()
-
Add photo to .pyui file
Hi, working on UI layout and want to know how to get a photo from my camera roll or my iCloud Drive to display in the UI grid.
Thanks,
Craig -
RE: Help with building an app at early stages
@mikael they aren’t named myInterface, but they are both named the same thing, GOapp.py and GOapp.pyui in the same folder
-
RE: Help with building an app at early stages
@cvp I’m not sure how to show that here, I don’t see adding a picture/screenshot option and my UI file only shows the grid layout. I thought I had accessed a code version before, but every button I press in the menu seems to take me everywhere but where the code is (using my iPhone, not a tablet).
-
Help with building an app at early stages
Hi,
I’m looking to get my pythonista code into app mode, and I’m looking for some advice from others. I created the UI folder so I have a UI file and a Python file. The only tutorials I can find are for different types of games.
I need to figure out how to incorporate my code into the UI layout. Thoughts?
This is my code, the console says I haven’t defined myInterface, so I need help with that.import ui import time from random import choice def intro(): print("The Guitar Oracle is listening.") time.sleep(2) def key (myInterface): viewSelector = myInterface.superview textFromTextBox = viewSelector['textview1'].text keys = ['C','F','Bb','Eb','Ab','Db','Gb', 'Cb','G','D','A','E','B','F#','C#'] key = input("Choose your key: ").capitalize() if (key == 'C'): print('You chose C, excellent') ask=input('Major or Minor?: ').lower() if (ask=='major'): cmajor = ['C Ionian: C – D – E – F – G – A – B','C Lydian: C - D - E - F# - G - A - B','C Mixolydian: C - D - E - F - G - A - Bb', 'C Maj Pentatonic: C - D - E - G - A'] levels= input('Choose your level (1, 2, or 3): ') validLevel = range(1,4) #provides range for acceptable levels 1, 2, or 3 if (levels.isnumeric()): levels = int(levels) if (levels == 1): question = choice(cmajor) print(question) elif (levels == 2): question = choice(cmajor),choice(cmajor) print(question) elif (levels == 3): question = choice(cmajor),choice(cmajor),choice(cmajor) print(question) if (ask=='minor'): cminor = ['C Dorian: C - D - Eb - F - G - A - Bb','C Phrygian: C - Db - Eb - F - G - Ab - Bb', 'C Aeolian: C - D - Eb - F - G - Ab - Bb','C Locrian: C - Db - Eb - F - Gb - Ab - Bb', 'C Harmonic Minor: C - D - Eb - F - G - Ab - B','C Melodic Minor: C - D - Eb - F - G - A - B','C Min Pentatonic: C - Eb - F - G - Bb'] levels= input('Choose your level (1, 2, or 3): ') validLevel = range(1,4) #provides range for acceptable levels 1, 2, or 3 if (levels.isnumeric()): levels = int(levels) if (levels == 1): question = choice(cminor) print(question) elif (levels == 2): question = choice(cminor),choice(cminor) print(question) elif (levels == 3): question = choice(cminor),choice(cminor),choice(cminor) print(question) if __name__ == "__main__": intro() practicing = True while practicing: #prompts the user to keep playing key(myInterface) viewSelector = myInterface.superview textFromTextBox = viewSelector['textview1'].text time.sleep(2) keepPracticing = input('Do you want to keep practicing (yes or no)? ') validUser = ['yes', 'y','sure','ok','k','okay'] #acceptable answers for keepPracticing if (keepPracticing not in validUser): practicing = False #terminates program/loop print('Goodbye') v = ui.load_view() v.present('sheet')
-
Proper function layout, calling
Trying to build a 3 function program:
- What key(music)?
- Major or minor?
3.What level (for practicing)?
Having trouble with local variables I think. The steps should be: get the key, decide between major or minor scales, then determine how many scales to provide, 1, 2, or 3?
I have this working properly without functions but believe there’s a cleaner way to write it.
from random import choice def key(): keys = ['A','B','C','D','E','F','G'] k1=input('Choose your key: ').upper() if k1 in keys: print('Ahh,',k1, 'excellent choice.') else: print('I do not understand your choice.') key() def tone(): major = ['Ionian: W,W,H,W,W,W,H','Lydian: W,W,W,H,W,W,H','Mixolydian: W,W,H,W,W,H'] minor= ['Dorian: W,H,W,W,W,H,W','Phrygian: H,W,W,W,H,W,W','Aeolian: W,H,W,W,H,W,W','Locrian: H,W,W,H,W,W,W','Harmonic Minor: W,H,W,W,H,W+H,H'] ask2 = input('Major or Minor: ') if (ask2=='major'): question = choice(major) answer=input(question).lower() elif (ask2=='minor'): question = choice(minor) answer=input(question).lower() def level(): ask = int(input('Choose your level(1, 2, or 3): ')) if (ask == 1): question = choice() answer=input(question).lower() print(answer) elif (ask == 2): question = choice(),choice() answer=input(question).lower() print(answer) elif (ask == 3): question = choice(),choice(),choice() answer=input(question).lower() print(answer) else: print('I do not understand your choice.') level() tone()
-
Find consecutive elements in a list
Trying to return True if there are duplicate items in a list.
Not working with numbers, and want to allow the user to make a list as long as they want...suggestions?user = input("What's on your list??: ") def has_consecutive(): items = user.split() #trying to split list into items to compare if (items[0] == items[+1]): #trying to compare one item to the next to find duplicates return True #return true if duplicates are found else: return False #return False if no duplicates are found has_consecutive()```
-
Adding characters to strings
Horrible at math (and probably Python) but trying to make a function that takes a word and adds an asterisk in between the letters. Trying with a 3 letter word, but the formula should handle any size word you give it.
Here’s what I have:word=str(input('Give me a word: ')) def starry_eyes(str): while word == (''): return ([],'*',[],'*',[]) ```
-
OOP Inheritance Problem
Thinking I set up this inheritance structure right, but getting an error that “ init() takes 1 positional argument but 15 were given.” Any thoughts?
import random #Player Info class Player: def __init__ (self, name, race, subrace, age, subclass,hair, eyes, height, weight, strength, speed, intelligence, knowledge, attack, defense,**kwargs): for key,value in kwargs.items(): setattr(self,key,value) self.name = name self.race = race self.subrace = subrace self.age = age self.subclass = subclass self.hair = hair self.eyes = eyes self.height = height self.weight = weight self.strength = random.randint(6,18) self.speed = random.randint(6,18) self.intelligence = random.randint(6,18) self.knowledge = random.randint(6,18) self.attack = random.randint(2,6) self.defense = random.randint(2,6) def __str__ (self): return ("Name: {}, Race: {}, Subrace: {}, Age: {}, Subclass: {}, Hair: {}, Eyes: {}, Height: {}, Weight:{}, Strength: {}, Speed: {}, Intelligence: {}, Knowledge: {}, Attack: {}, Defense: {}").format(self.name,self.race,self.subrace, self.age,self.subclass,self.hair,self.eyes, self.height,self.weight,self.strength, self.speed,self.intelligence,self.knowledge, self.attack,self.defense) p1 = Player("Rob", "Human", "Hunter", "25", "none", "Brown", "Green", "72in","185"," "," "," "," "," "," ") print(p1) #Special Classes for Players class Vampire(Player): def __init__ (self): data = { "strength": random.randint(14,18), "speed": random.randint(14,18), "intelligence": random.randint(14,18), "knowledge": random.randint(14,18) } super().__init__(**data) p2 = Vampire("Jon", "Vampire", "Archaea", "500", "none", "Black", "Red", "84in","225"," "," "," "," "," ") print(p2)
-
Music Scale Generator
Hi,
Getting an error that “mode object has no attribute scale_steps” when I run this, but I think everything is ok. Does anyone see where there is a disconnect??legal_mode = [ "Ionian", "Dorian", "Phrygian", "Lydian", "Mixolydian", "Aeolian", "Locrian"] stepping = [2, 2, 1, 2, 2, 2, 1] major_mode = ["Ionian"] class Mode(): def __init__(self,title): self.title = title self.ismajor = title in major_mode tonic = legal_mode.index(title) self.stepping = stepping[tonic:]+stepping[:tonic] def __str__(self): return "Title: {}, Major{}".format(self.title, self.ismajor) def scale_steps(self): return "Half-steps{}".format(''.join(str(c) for c in self.stepping)) mode1 = Mode("Ionian") print(mode1) print(mode1.scale_steps()) mode2 = Mode("Dorian") print(mode2) print(mode2.scale_steps())```