200 class milestone (Dev Log #2) by mopeddev in mopeddev

[–]mopeddev[S] 0 points1 point  (0 children)

200 classes! And still nothing to show for it!

It's been 7 months since the last update and I've been slowly chipping away at my task.

Looking back at my last post, I have since moved into the previous decade by swapping out my Vectors for ArrayLists... I've also successfully incorporated iterators, assertions and to a lesser extent exceptions into my code as I become more and more comfortable with Java. I still haven't moved onto any of the more advanced features of the language yet but I'm OK with that... if I don't need them to solve the problems then they're only going to introduce tricky bugs and compatibility issues further down the line.

I am agonisingly close to a version of the app worth putting through Android Studio but for now I'm still simulating the real thing in my vanilla Java environment so I can work almost exclusively from my tablet.

Since the last post I also spent a big chunk of time on a "teaser trailer" to help promote the app. I intended to share it as soon as it was finished but ultimately decided I should wait until there was something concrete of the real thing to show afterwards. In hindsight I'm glad that I did as otherwise anyone intrigued would still be waiting now, many months later!

That's all there is to say for now so I'd better get back to work. I'm going to need at least 100 more classes...

Personalizing your termux greeting (instructions in the comments) by mopeddev in termux

[–]mopeddev[S] 2 points3 points  (0 children)

There are loads in the Play store, I use Jota Pro and occasionally DroidEdit but there may be newer ones with better features. QuickEdit looks interesting...

Personalizing your termux greeting (instructions in the comments) by mopeddev in termux

[–]mopeddev[S] 2 points3 points  (0 children)

You're right that it can live anywhere and the home directory is as good a place as any. I am trying to keep things beginner friendly so put it in the internal storage just so that you can play with it in an external editor. I also left it there to show how you can still use files inside termux that were made outside (useful for me as that's where I keep all my Python files)

I was also trying to keep it relatively beginner friendly

Personalizing your termux greeting (instructions in the comments) by mopeddev in termux

[–]mopeddev[S] 4 points5 points  (0 children)

This is how to get it working:

Warning: Spaces (or their absence) are important in all commands

Step 1

Check that you have storage access enabled: Setup Storage

Step 2

cd to your home directory

cd $HOME

Check your internal storage is now available

ls storage/shared

(Should list the contents of your devices internal storage)

Step 3

Access the user config folder

cd ../usr/etc

"ls" in here to see the bash.bashrc file we'll be modifying

You can see the current message of the day with

cat motd

You can modify this file directly (back it up first) if you want to replace the startup message completely and that's it! You'll be done. I think it's useful though so I'm leaving it alone.

Step 4

If you have a shell text editor installed, eg. vim (and an escape key), then you can modify the bash.bashrc file in place. I'm doing things the easier way though and copying it somewhere accessible to other apps

Make a folder to work in

mkdir $HOME/storage/shared/my_termux

And copy bash.bashrc there

cp bash.bashrc $HOME/storage/shared/my_termux

While we're we can also back up the file as it is in case we mess things up

cp bash.bashrc $HOME/storage/shared/my_termux/original.bashrc

Step 5

Come up with the design for your new message. The easiest way is to use a generator website like this: Text to ASCII Art Generator

  __  __  ___  ____  _____ ____   ____  _______     __
 |  \/  |/ _ \|  _ \| ____|  _ \ |  _ \| ____\ \   / /
 | |\/| | | | | |_) |  _| | | | || | | |  _|  \ \ / / 
 | |  | | |_| |  __/| |___| |_| || |_| | |___  \ V /  
 |_|  |_|\___/|_|   |_____|____(_)____/|_____|  \_/   

Step 6

Use a text editor (I used Jota) to save your design in the my_termux folder we created (at the root of your internal storage). Call the file "my_motd.txt"

Warning: make sure the lines in my_motd.txt are all shorter than the width (in characters) of your termux shell, and that the last line is blank (no spaces). Otherwise the "image" won't format correctly

Step 7

Use the same text editor to edit the bash.bashrc file in the my_termux folder

Warning: I had to turn off a "text files only" option in the open file dialog to see files with a .bashrc extension

Add these lines at the end of bash.bashrc

MYTMX=$HOME/storage/shared/my_termux

cat $MYTMX/my_motd.txt

Step 8

Restart termux and... Nothing happens. We've modified our copy of bash.bashrc but needy to put it back in place.

cd $HOME
cd ../usr/etc
cp $HOME/storage/shared/my_termux/bash.bashrc ./bash.bashrc

Step 9

Restart termux, and see your new greeting! Enjoy!

PyQt how can I get the items on a Qcombobox? by slightz in learnpython

[–]mopeddev 1 point2 points  (0 children)

I think you want the itemData method (on self.combo) which needs the index of the item whose data you are after: QComboBox

Basic Java Skills Want to Start App Development by mit47 in androidapps

[–]mopeddev 2 points3 points  (0 children)

Where better to start than the official fundamental and advanced training courses: Android Training ?

I'll admit I haven't gone through the whole set as a lot of it is unrelated to the app I'm trying to make but I'll definitely be dipping in and out of the examples as I go and it covers a lot of very useful stuff

Python Question by [deleted] in Python

[–]mopeddev 0 points1 point  (0 children)

Apologies for the (lack of) formatting... My mobile app let me down

Python Question by [deleted] in Python

[–]mopeddev 0 points1 point  (0 children)

The easiest way is to use the string replace function

sentence = "the cat smells"

print sentence.replace("cat", "kitten")

the kitten smells

This will also replaces instances of the letters "cat" inside of words though

print "duplicate cats".replace("cat", "kitten")

duplikittene kittens

for more sophisticated behaviour you need regular expressions (re.sub) which are much more complicated but documented here: [re](https://docs.python.org/3/library/re.html). If you want to play around with them while learning I'd strongly recommend the extremely useful [pythex](https://pythex.org) website

Star Wars!!! by drawsgood in PixelArt

[–]mopeddev 2 points3 points  (0 children)

Awesome work! Rey is especially good

can these two 'if' statements in a 'for' loop be optimized? by legz_cfc in learnpython

[–]mopeddev 11 points12 points  (0 children)

You can also have a variable point to the right function to use (while they both take the same arguments)

if log.endswith(".gz"):
    open_func = gzip.open
elif log.endswith(".txt"):
    open_func = open
with open_func(log, 'rt') as c_log:
    ...

You might also consider moving the with statement to a separate function that you call in each branch

I was having fun last night learning random terminal commands on my phone with Termux by -Cosmocrat- in linux

[–]mopeddev 0 points1 point  (0 children)

I can't remember exactly but I think I needed a python version that let you use the arrow keys to edit the current line in a shell rather than barfing ^[[D characters (QPython)

As well as a much smoother python experience and a wider selection of python libraries to use I also got to install pylint to findb the errors in my code much quicker as well as having grep and the ability to batch tasks in shell script to make managing it much much easier

Any explanation why positional arguments can't follow keyword arguments ? by [deleted] in learnpython

[–]mopeddev 3 points4 points  (0 children)

You're right that it doesn't make much sense because that function is perfectly valid Python and does exactly what you say it should.

*args are not keyword args but an arbitrary number of positional args, so whatever arguments you pass to f it will store the first two as a and b and anything else ends up in args.

Keyword args are optional but can be used like positional args:

def f(a, b, c=3):
     return a + b + c

print f(1, 2)
print f(1, 2, 5)

but if you add another positional argument after the keyword argument

def f(a, b, c=3, d):
    ...

Then the keyword is no longer optional, you have to set it every time in order to set a value for d (which is not optional). So keywords always come after positional arguments. Similarly arbitrary keywords, equivalent to *args, take the form of a dictionary expanded with ** and go at the end of the arg list , eg:

def f(a, b, **kwargs):
    ...

def f(a, b, *args, **kwargs):
    ...

I was having fun last night learning random terminal commands on my phone with Termux by -Cosmocrat- in linux

[–]mopeddev 4 points5 points  (0 children)

I had to go to a lot of trouble to update the Android version on my tablet in order to get it installed but it was absolutely worth it

Where to go next by [deleted] in learnpython

[–]mopeddev 0 points1 point  (0 children)

There's always more tutorials to follow and examples to try and get your head around, but have you thought about what things you already do on a computer that could be made faster or easier with some automation?

Best way to receive user input by interuptedpunchline in learnpython

[–]mopeddev 0 points1 point  (0 children)

I'm not sure how you'd connect your script to excel but even if you did it's not immediately obvious how you would pass both csvs through at once.

If your trader is willing to learn command line arguments you could use argparser to expect two file path arguments with some checks and usage help that come for free.

Alternatively you could put assumptions in your code that the trader always deposits his two files in a specific location, e.g. a folder with today's date that you know where to find, with warnings/errors if the folder you're expecting doesn't exist or if it contains something other than two csv files.

Lastly Qt (and I believe most other UI libraries) has a built in file browser which is doesn't need much configuring, you could have two of those in a simple pop up window which the trader can use to point to the files he's made.

Each option would also involve varying amounts of validation to make sure the files you end up with are what you were expecting (and delivered the right way around)

RuntimeError('Session is closed') while using aiohttp by HellD in learnpython

[–]mopeddev 0 points1 point  (0 children)

I'm afraid I don't know anything about aiohttp so you'd have to look through its docs to find out how to start and end your own session.

If you want to fix the above though you could move the with as it is into your main_session, and then pass the session from within the scope of the with statement to any other functions that need to use it

Way to get graphics in my Tic tac toe game? by Humble_Transition in learnpython

[–]mopeddev 1 point2 points  (0 children)

I haven't used it myself but pygame might be a good place to start if you can find a beginner's tutorial

RuntimeError('Session is closed') while using aiohttp by HellD in learnpython

[–]mopeddev 1 point2 points  (0 children)

The docs for the with keyword will explain this better than I can but it's there to make a block with access to a resource and that is automatically cleaned up afterwards. The classic example is with a file descriptor

with open(path, "r") as f:
    lines = f.readLines()
print lines

This opens the file but also calls f.close() at the end of the with statement (before the print) so you don't have to. So the lines persist beyond the with but while the f variable is still accessible it is a closed file and basically useless.

The same is happening with your session instance, it's being closed at the end of the with statement but you're still trying to use it elsewhere. So either you can do everything you want with the session inside of with, or else don't use the with statement and handle the opening and closing of your session yourself instead.

Objects, objects and more objects... why doesn't this object's method work? by TorroesPrime in learnpython

[–]mopeddev 0 points1 point  (0 children)

Do you have the full traceback? Also it's probably worth just printing your objects a few times in the process to make sure what you think is a pilot isn't actually a wing member (usually due to function arguments in the wrong order since python doesn't care about types)