Does it have something to do with which apps the files are stored in? On my device (iPhone SE, iOS 10.3.3)
dialogs.pick_document()lets me pick any file from most apps (including files in the "main" iCloud Drive part that is not in any app folder), but in some apps (for example Pages) no files can be selected at all.
Is the file with your code called
discord.pyperhaps? If so, you need to rename it - otherwise when you say
import discord, it will import your own script instead of the
Also just FYI, it's not possible to have a Python script run while Pythonista is in the background - iOS does not allow apps to run in the background for a long time. I don't know anything about writing Discord bots, but I assume that you have to keep your script running in order for the bot to work. So if you want your bot to always run, without having to start it manually first, you're probably better off running it on a regular computer instead of a mobile device.
This comes from a new feature in iOS 11, called "smart punctuation". It changes some punctuation into nicer/more "correct" characters, for example it replaces "--" (two minuses) with "–" (an "em dash"), as you discovered. This is nice when writing normal text, but causes problems when writing code. You can turn this feature off in the iOS Settings app, under General > Keyboard. (If you have a hardware keyboard, you may also have to turn it off again under the "Hardware Keyboard" section.)
If this doesn't work, you can probably copy and paste the text from the instructions that you're following. The pasted text shouldn't be changed by any of the iOS text replacement features.
There's no way for Pythonista to interface with the iOS Mail app - iOS doesn't provide any APIs for that. You could instead use the
imaplibmodule to access your Gmail mailbox directly. But in any case there's no way to set up a regular task like that - Pythonista can't run in the background for very long before iOS pauses/terminates it.
I don't use Gmail very much, but maybe there's an option in their web interface to empty the trash regularly, or delete mails that were left in the trash for some amount of time. Desktop mail clients (like Thunderbird or the macOS Mail app) usually have that kind of feature as well, so if you have one set up, you can probably configure it there.
For reading from and writing to the iOS Photos library, you can use Pythonista's
photosmodule. For example you can use
photos.pick_image()to select a single image using the standard image picker, which is returned as a PIL image. If you want to automatically get all images from an album, you can use
photos.get_albums()to access the list of albums in your library. Each album has an
assetsattribute, which contains
Assetobjects for each photo/video in the album. To convert an
Assetto a PIL image, you can use the
You can also manually import assets from the Photos library into Pythonista as files: in the file browser, tap on the "+", then "Import...", then "Photo Library".
For playing sound, Pythonista has a
soundmodule. The interface is pretty straightforward, you use
sound.play_effect("path/to/sound/file")to play a file.
Pythonista also comes with some built-in sound effects. To use them, tap the "+" button (on iPad it's in the editor toolbar, on iPhone it floats over the keyboard). This brings up Pythonista's media picker. On the "Sounds" tab, you get a list of built-in sound effects. When you select one, its name is inserted into your code as a string, which you can pass to
play_effectto play that sound.
super()without any arguments only works in Python 3. The equivalent Python 2 code is
super(<classname>, self), where
<classname>is the name of the class that you're currently in. This version of
superworks on both Python 2 and 3.
Note that you have to write the class name in the
supercall by hand. You cannot use
self.__class__- if you do, the
supercall won't work properly. (See this Stack Overflow question.)
In line 10, you wrote
self.heads = heads, but you haven't set the variable
self.headsdon't mean the same thing - and if they did, that assignment wouldn't do anything.) I can't help much with that - I don't see any other place in your code where a
headsvariable is used.
As for the other two errors - where did you get them from? Python doesn't usually give multiple errors at once. If you changed something in your code and that caused a different error, then it's helpful if you tell us what you changed. Also, always include the error message - just "line 52" doesn't tell us anything about what went wrong.
When you're posting code, it also helps if you put it in a code block, so the forum displays it as code and doesn't read it as formatted text. The easiest way to do that is with the "</>" button in the toolbar when you reply. You can also do it by hand, by putting a line with ``` (three backticks) before and after your code.
You're missing a space between the
If that doesn't fix the error, can you post your entire code? (Or if your code is very long, only a few lines before and after the syntax error.) Sometimes when Python finds a syntax error, the location that it shows you isn't exactly where you made the error. This can happen when you forget to close a parenthesis for example, depending on your code, Python might not notice the missing parenthesis until a few lines later.
This could be because of iOS 11's "smart punctuation" feature, which messes up quotes, dashes, and other punctuation. (Well, in normal text it's nice, but when programming it's annoying.) Maybe you've already disabled it for the onscreen keyboard, but you may have to disable it again for the hardware keyboard. (Since iOS 10, some keyboard settings are tracked separately for onscreen and hardware keyboards. The "smart punctuation" setting might be one of them.)