Python Thread - Raspberry Pi General

I have created this thread so that everyone can post and share tips, tricks, guides and code snippets.
I found Python about a year ago and liked that it is open source, cross platform and structured. Along with the community behind it and the fact that lots of applications that I use are built on Python.
I am only a beginner at Python programming, but I have learnt so much from it, which I can take to other programming languages.
So, that's why this thread is dedicated to Python.

I will also post links to online python resources.
Sent from my GT-S5830 using Tapatalk 2

If you are looking to learn python, learn python the hard way is a great book to get you started.
Sent from my HTC Evo V 4G

Some of the Python resources I use:
Codecademy Python Track
The New Boston Python Videos
The Official Python Documentation
The Official Python Wiki
Python Tkinter GUI Documentation
I will try and post some more resources later.

I use Python for Dummies (ISBN: 978-0-471-77864-6) and the Magpi (Just contributed to the Kickstarter).
Sent from my GT-S5830 using Tapatalk 2

The New Boston videos are great. I leant a bit of Java thanks to them.
Sent from my GT-S5830 using Tapatalk 2

shimp208 said:
Some of the Python resources I use:
Codecademy Python Track
The New Boston Python Videos
The Official Python Documentation
The Official Python Wiki
Python Tkinter GUI Documentation
I will try and post some more resources later.
Click to expand...
Click to collapse
invent with python is also a very good one and its free: http://inventwithpython.com/

Related

Visual Basic, C#, or Java programming?

I am currently working on my associates and I need 4-5 credits in BPC, CIS, and some others. I was wondering which classes would better suite me if I wanted to start getting into the hacking and rom building scene.
I have all ready taken a class on C++ so I have a basic starting point on how programming languages operate, but that class didn't transfer to the school I'm currently going to. So my question is, which classes would better suite me (I only need 2 in order get my degree seeing as they are 3 credit classes) to assist with becoming better developer for android?
all insight is welcome, but searching for developers insight...
Java would be best if you want to work with Andriod, as a lot of the code is java, and what isn't in java is mostly C I believe, and possibly a few other languages thrown in.
imnuts said:
Java would be best if you want to work with Andriod, as a lot of the code is java, and what isn't in java is mostly C I believe, and possibly a few other languages thrown in.
Click to expand...
Click to collapse
In the android source there should be c++ besides Java. As for kernel it's mostly C and ASM
Sent from my Incredible 2 using XDA App
FORTRAN 77
Seriously, though, you might consider adding a Linux course or two if they're available and you haven't done so already...
Has anyone seen John Connor?
Checked for linux and there was none. That was my first search. Now should I do c++ and the course that follows c++2. Or a little of both. C and Java. There is also a Java level 2
Sent from my SCH-I500 using XDA App

Does android support c++

As im now beginning too learn and compile in c++ and objective c i was wandering does android support it could i build a game in openGL and c++ or is it strictly java? thanks
Also i want to be able to work on the go but the best environment i could find was this https://play.google.com/store/apps/details?id=com.didactic.DeuterIDE&hl=en
any suggestions please don't say run Ubuntu natively.
sorry if this post is better suited in Q an A or Development
gears177 said:
As im now beginning too learn and compile in c++ and objective c i was wandering does android support it could i build a game in openGL and c++ or is it strictly java? thanks
Also i want to be able to work on the go but the best environment i could find was this https://play.google.com/store/apps/details?id=com.didactic.DeuterIDE&hl=en
any suggestions please don't say run Ubuntu natively.
Click to expand...
Click to collapse
Take a look at the Android NDK (Native Development Kit). You can build native code and compile with C/C++, although it is best integrated with a Java project to build the final APK. You can't use Objective-C, however. We don't have Cocoa Touch haha
I personally haven't used the NDK but I've looked at it and it does provide a complete ARM toolchain. NVIDIA also provide some additional Tegra profiling tools that integrate with the NDK.
blackthund3r said:
Take a look at the Android NDK (Native Development Kit). You can build native code and compile with C/C++, although it is best integrated with a Java project to build the final APK. You can't use Objective-C, however. We don't have Cocoa Touch haha
I personally haven't used the NDK but I've looked at it and it does provide a complete ARM toolchain. NVIDIA also provide some additional Tegra profiling tools that integrate with the NDK.
Click to expand...
Click to collapse
hmm thanks so objective c is out most likely i will integrate it with Java to since my c skills are not great yet....for a mobile environment you recommend Android NDK?
gears177 said:
hmm thanks so objective c is out most likely i will integrate it with Java to since my c skills are not great yet....for a mobile environment you recommend Android NDK?
Click to expand...
Click to collapse
Well, the SDK for proper app development (in java mainly) but you can integrate that with the NDK for native code in C/C++
Sent from my A500 using Tapatalk 2
blackthund3r said:
Well, the SDK for proper app development (in java mainly) but you can integrate that with the NDK for native code in C/C++
Sent from my A500 using Tapatalk 2
Click to expand...
Click to collapse
thanx will do so if i got this right building a game in c++ in openGL will work but recommended to integrate it into java for the apk

[Dev][RELEASE][Lib/Java] JDroidLib Java ←|→ Android Communications Library

Hey there,
many of you are probably familiar with @regaw_leinad's AndroidLib.
It is a really nicely coded, and easy-to-use .Net class library, which allows real easy communication with Android devices.
regaw_leinad said:
AndroidLib is a .NET assembly written in C# (C-Sharp) that easily handles communication between a connected Android device and your program.
Click to expand...
Click to collapse
However, it has a downside. That downside being; it only works with .Net languages. .net languages include:
Code:
# Visual Basic
# C#
# F#
# Visual C++
# ASP.Net
As you might have guessed, Java does not belong to the .Net language set.
And as I moved from .Net to Java (allows my projects and libs to become available to a wider audience), I don't have the privilege to use AndroidLib, which is a real bummer.
This is why I have started JDroidLib.
​
Edit (08.10.2017): JDroidLib is being replaced by JDroidLibv2!
For anyone coming across this thread; this version of JDroidLib, while still available, is considered obsolete and is being replaced by JDroidLibv2!
https://forum.xda-developers.com/android/software-hacking/lib-jdroidlibv2-t3684697
EDIT: 01.03.2014
JDroidLib has undergone some major updates, with loads of kinks fixed, and features revamped.
See the lists below for more info. (Everything has changed, there).
Oh, and the code has a kind of easter egg
Current features:
Code:
# Execute any type of ADB command from a single method.
(This method always returns output, but you can execute the method, without grabbing it).
# Execute any fastboot command frmo a single method. (Same returns as above.)
# Install ADB/fastboot to either fixed, or custom location. (On MAC OS/Linux: Binaries are automatically chmod-ed!)
# Pull entire build.prop from device to hard drive
# Get single build properties ([B]!!![/B])
# Push build.prop back to device.
# Reboot device (5-way/ADB + fastboot)
# Get list of devices. (Returned as generic List<String>)
# Get device information (Battery, SU, BusyBox, CPU - MORE COMING!)
# Get device state
# Start ADB server
# Stop ADB server
# Restart ADB server.
# Much, much more. See JavaDocs for more!
Current bugs:
There's a weird bug in the Battery department, where the loaded battery level is 0. Looking into it! Fixed.
Slight bug in reboot methods, device isn't rebooting. Fixed.
Click to expand...
Click to collapse
Planned features:
Code:
# Get phone/WiFi/BlueTooth/etc. information
# And anything else that comes to mind!
License:
Code:
/*
* Copyright (C) 2013 Simon/Beatsleigher.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
Source code:
To get a copy of the source code, visit my GitHub
There will be no pre-compiled JARs. To get a JAR, you have to download and compile the source.
The IDE used is NetBeans 8.0 with JDK 7
To download NetBeans, visit http://netbeans.org
JDroidLib Documentation:
http://team-m4gkbeatz.eu
How to Use JDroidLib:
http://www.youtube.com/watch?v=dRSwailf7GI
Thanks:
Thanks to @regaw_leinad for having the original idea!
Thanks to you, XDA, for taking the time and looking at my programs/libs. Much appreciated!
XDA Portal Story 04.12.2013
Newer XDA Portal Story 03.03.2014
Have fun with JDroidLib and don't forget to contribute your own code!
This project made it to the Home Page!
http://www.xda-developers.com/android/a-new-android-communications-library-jdroidlib-java/
Congrats mate
Subscribed!
zylor said:
This project made it to the Home Page!
http://www.xda-developers.com/android/a-new-android-communications-library-jdroidlib-java/
Congrats mate
Subscribed!
Click to expand...
Click to collapse
(^-^) Awesome
But where did that other thread come from?
You know, you could always contribute to CASUAL. We use Java and NetBeans as well and we are already a few years ahead of you. We could pull out the ADB/fastboot/busybox/Heimdall portions of CASUAL to distribute separately, by making some small changes to our make file and would have what you're going for here.
AdamOutler said:
You know, you could always contribute to CASUAL. We use Java and NetBeans as well and we are already a few years ahead of you. We could pull out the ADB/fastboot/busybox/Heimdall portions of CASUAL to distribute separately, by making some small changes to our make file and would have what you're going for here.
Click to expand...
Click to collapse
Wow. Never would have thought you'd reply to or even look at one of my threads!
It's a good idea. I'll have a think about it. I'm going to keep working on this, mainly because someone (or even I) could eventually port it to C/C++ if they need to.
Beatsleigher said:
Wow. Never would have thought you'd reply to or even look at one of my threads!
It's a good idea. I'll have a think about it. I'm going to keep working on this, mainly because someone (or even I) could eventually port it to C/C++ if they need to.
Click to expand...
Click to collapse
hey I've just done a draft for a python adb (PyAdb) which removes entirely the dependence of the adb binary. when you get into it, it's actually quite simple to replicate it. I've added reference links in my thread as well, and the python is so simple you can see how it all works
http://forum.xda-developers.com/showthread.php?t=2574326
ping me if you want any help with anything. I'm getting on with my java studies so I may be able to help with porting it over
cybojenix said:
hey I've just done a draft for a python adb (PyAdb) which removes entirely the dependence of the adb binary. when you get into it, it's actually quite simple to replicate it. I've added reference links in my thread as well, and the python is so simple you can see how it all works
http://forum.xda-developers.com/showthread.php?t=2574326
ping me if you want any help with anything. I'm getting on with my java studies so I may be able to help with porting it over
Click to expand...
Click to collapse
The main reason I coded this is for use in my own programs, coded in Java.
I guess the Python wrappers coded by you and the other member, are for use with the Python interpreter.
But I guess I could help port stuff over and you could help with JDroidLib.
Sent from my GT-I9505 using XDA Premium 4 mobile app
Beatsleigher said:
The main reason I coded this is for use in my own programs, coded in Java.
I guess the Python wrappers coded by you and the other member, are for use with the Python interpreter.
But I guess I could help port stuff over and you could help with JDroidLib.
Sent from my GT-I9505 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
Sorry you got the wrong end of the stick. The one by me is an adb client in python, not a wrapper. I was suggesting look at the methods it uses so the same can be done for JDroidLib, without needing a dependence on the adb binary. It's just commands passed via TCP
Sent from my Nexus 7 using Tapatalk
cybojenix said:
Sorry you got the wrong end of the stick. The one by me is an adb client in python, not a wrapper. I was suggesting look at the methods it uses so the same can be done for JDroidLib, without needing a dependence on the adb binary. It's just commands passed via TCP
Sent from my Nexus 7 using Tapatalk
Click to expand...
Click to collapse
Ahhh. I gotcha. Sure. If you want, check out the source and see what you can do. I'll take a look at it as soon as I've finished my Tekkit server and got DetectCPUv3 done.
Sent from my GT-I9505 using XDA Premium 4 mobile app
JDroidLib is back, and beter than ever!
Hey guys,
I was asked by a few friends and other people, if I had abbandoned JDroidLib, because I wasn't updating it for so long, so I haven't abbandoned it, nor have I abbandoned any other projects of mine, which are currently being ported to Java, it's just time consuming, and I'm looking for jobs at the moment, so I'm not on as much, and I don't have that much time to do things.
But, I have picked up JDroidLib again, and added some new features!
Basically, I've re-written the entire thing in under a day, because the code that was originally in there was real messy and I thought I may as well.
The new features include:
Code:
Device listing
Comand execution (now made really simple and squashed into two-three methods)
Rebooting the device (now one method, and uses internal enums)
I've revamped the installer, so other programs can install the binaries to their desired location, however, for operation, the default location will be used.
And (finally) I've got the Battery class, so developers can easily get battery stats!
Also, I've added a BuildProp class, which allows you to pull the file to a location on the HDD, read individual props and push the file back!
Currently, I'm sorting out the CPU class, which will, similarly to the Battery class, get CPU info, like currently running processes and CPU load.
So, check out the GitHub repo, and watch it to get the latest stuff!
Feel free to add your own code, classes, whatever and I can't wait to release this puppy into the wild! (Metaphorically speaking, that is... )
### UPDATE ###
JDroidLib has gotten a huge update!
This update fixes a major bug in EVERY program using JDroidLib in Windows systems!
Please pull and build a new copy of JDroidLib, before continuing with any of your work!
Although I'm not a big fan of Java, I prefer C#
Your library made me rethink of porting Droid Manager (Which uses AndroidLib) to Java in-order to make it available for every one.
Let's see what I can do :fingers-crossed:
Thanks for your efforts :highfive:
OmarBizreh said:
Although I'm not a big fan of Java, I prefer C#
Your library made me rethink of porting Droid Manager (Which uses AndroidLib) to Java in-order to make it available for every one.
Let's see what I can do :fingers-crossed:
Thanks for your efforts :highfive:
Click to expand...
Click to collapse
-- Post deleted --
Reason: Didn't read post correctly and I take back what I said.
Sent from my GT-I9505 using XDA Premium 4 mobile app
Beatsleigher said:
-- Post deleted --
Reason: Didn't read post correctly and I take back what I said.
Sent from my GT-I9505 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
Although I didn't read what was written before :angel:
I would like to ask you, have you ever written or know something about using Java to write a service that can run on Linux and Mac?!
I only know how to write a windows service using C# Unfortunately
OmarBizreh said:
Although I didn't read what was written before :angel:
I would like to ask you, have you ever written or know something about using Java to write a service that can run on Linux and Mac?!
I only know how to write a windows service using C# Unfortunately
Click to expand...
Click to collapse
As far as I'm aware, it's just a program that runs in the background. So it shouldn't be difficult to code. Maybe a few threads and things, and it should work. Otherwise, Google is your friend. Personally, I've never written a service in Windows or BSD, so I have no idea how they work. But I can imagine it shouldn't be too difficult.
Sent from my GT-I9505 using XDA Premium 4 mobile app
Beatsleigher said:
As far as I'm aware, it's just a program that runs in the background. So it shouldn't be difficult to code. Maybe a few threads and things, and it should work. Otherwise, Google is your friend. Personally, I've never written a service in Windows or BSD, so I have no idea how they work. But I can imagine it shouldn't be too difficult.
Sent from my GT-I9505 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
well coding isn't difficult, I suppose I will google it, since writing the core of the service isn't difficult, it's just how I do I do a service written in Java :fingers-crossed:
OmarBizreh said:
well coding isn't difficult, I suppose I will google it, since writing the core of the service isn't difficult, it's just how I do I do a service written in Java :fingers-crossed:
Click to expand...
Click to collapse
You'll manage, I'm sure
If you need any code examples, check out my UniversalAndroidToolkit repo on GitHub. It's all commented and documented, and I think I write pretty clean code, so it shouldn't be too hard to figure out
Sent from my GT-I9505 using XDA Premium 4 mobile app
Beatsleigher said:
You'll manage, I'm sure
If you need any code examples, check out my UniversalAndroidToolkit repo on GitHub. It's all commented and documented, and I think I write pretty clean code, so it shouldn't be too hard to figure out
Sent from my GT-I9505 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
Thanks a lot I really appreciate your help
I will make sure to browse your git repo :highfive:
OmarBizreh said:
Thanks a lot I really appreciate your help
I will make sure to browse your git repo :highfive:
Click to expand...
Click to collapse
No probs. If anything's unclear, just shoot me a PM and we'll get things sorted
Beatsleigher said:
No probs. If anything's unclear, just shoot me a PM and we'll get things sorted
Click to expand...
Click to collapse
Thanks man, I really appreciate it ::highfive:

Creating An Android App with No Java Experience

Hi everyone!
I hope everyone is having a great Christmas. I just got a nexus 7 for Christmas and really want to make an android app now. I've learned other languages before like HTML 5, CSS3, but not java. How should I go about learning java and then making an app? Thanks and enjoy the break!
Sent from my Nexus 7 using xda app-developers app
In my opinion best thing is to buy a book about developing android apps.
---------------------------------
Phone : Samsung Galaxy Mini S5570
OS:
•AOSP ICS Touchwiz V5 by A_U
•Android 4.0.4
•Baseband XWKS2
•Kernel: 2.6.37.6 Badass v1.9 by alin.p
•Recovery CWM v4.0.0.5
Mods:
PureAudio, Mounts2SD, ODEX through Universal ODEX script, AdBlock by AdAway
---------------------------------
Gesendet von Tapatalk
Sorry, html nor css3 is comparable with java!! If you know JavaScript or PHP that would be an advantage.
Don't buy a book about android developing: you'll get frustrated! Learn java first: It isn't as hard as you think after a week: Don't give up. If you know java, android will be much more easy!
Regards
EmptinessFiller said:
Sorry, html nor css3 is comparable with java!! If you know JavaScript or PHP that would be an advantage.
Don't buy a book about android developing: you'll get frustrated! Learn java first: It isn't as hard as you think after a week: Don't give up. If you know java, android will be much more easy!
Regards
Click to expand...
Click to collapse
What's the best way to learn java?
Sent from my Nexus 7 using xda app-developers app
way many java tutorials are available on the net.
And java is very easy language to learn, and developing android is very easy as well.
TIProgrammer84 said:
What's the best way to learn java?
Sent from my Nexus 7 using xda app-developers app
Click to expand...
Click to collapse
I always recommend the Head First Java book.
krikor1 said:
way many java tutorials are available on the net.
And java is very easy language to learn, and developing android is very easy as well.
Click to expand...
Click to collapse
Do you have some tutorials links regarding Java for android ? I am looking for a good tutorial to start but with all the options I'm scared of wasting my time with tutorial that are too complicated or just bad...
The "Programming Mobile Applications for Android Handheld Systems" course starts on Coursera on 21-th january. May be it will be useful for you.
Java for Android is slightly different from regular Java. That is, the programming language itself is the same, but some of the packages (libraries) are different.
I think it's best to start with regular Java (for desktop apps), because there's a lot more books, tutorials and other resources to get you started. Once you know the basics of the Java language, you can then move to Android.
I can recommend Netbeans as a good IDE for starting with Java development.
The official IDE for Android is Eclipse, with a special Android plugin provided by Google. I don't find Eclipse very userfriendly, and it is not that stable either, so I don't think it's that good for beginners.
Some code I develop for Android today, I develop with Netbeans as a regular Java app first, then import the code into Eclipse and modify it to work for Android. But that's mostly the 'business end' code (I mainly develop graphical/rendering stuff...). UI code is entirely different for regular Java and Android, so it wouldn't make sense to do that in Netbeans first.
Youtube or Amazon will help you.
For learning Java I can recommend the newboston videos on youtube, his Android series even explains the java in good detail.
There are some good books for java, check Amazon reviews for the best ones. I like the Dietal How to Program, Java: The complete reference, and Java for Dummies.

[TUTORIAL] Write simple games (Flappy Bird) using Basic4Android and LibGDX

I've written a tutorial showing in easy steps how to write a Flappy Bird Clone using Basic4Android and the LibGDX engine.
Check it out here:
http://www.easyandroidcoding.com
I also keep a programming blog here:
http://www.coffeeinducedgames.co.uk
I just wanted to post a short update to this post:
I've also uploaded source code for a matching game using LibGDX and Basic4Android, it's called Orchard Crush and it's on the play store:
Get the source code here: https://dl.dropboxusercontent.com/u/8673694/OrchardCrush_public.zip
See the game here: https://play.google.com/store/apps/details?id=uk.co.coffeeinducedgames.orchardcrush
Basic4Android for those who don't know it, is a Visual Basic inspired language for writing appps for Android. It compiles to Java before using the ADK to compile to Android bytecode so your appps run at the same speed as if you'd written them directly in Java using Eclipse, except it's MUCH easier to learn and use to write apps.
It does cost money to buy B4A but you can claim a 30% discount if you purchase it through the www.easyandroidcoding.com site and use the voucher code: andymcadam
VOS said:
I've written a tutorial showing in easy steps how to write a Flappy Bird Clone using Basic4Android and the LibGDX engine.
Check it out here:
http://www.easyandroidcoding.com
I also keep a programming blog here:
http://www.coffeeinducedgames.co.uk
Basic4Android for those who don't know it, is a Visual Basic inspired language for writing appps for Android. It compiles to Java before using the ADK to compile to Android bytecode so your appps run at the same speed as if you'd written them directly in Java using Eclipse, except it's MUCH easier to learn and use to write apps.
It does cost money to buy B4A but you can claim a 30% discount if you purchase it through the www.easyandroidcoding.com site and use the voucher code: andymcadam
Click to expand...
Click to collapse
I've just uploaded part 8 of the series which completes it.
I've added the final part of the series on writing a Flappy Bird clone. Now it included sounds effects, a title screen, and a highscore file.
Wow
I am gonna try it soon
I can't wait to try this out in a way I can understand! I code in vb.
Sent from my HTC One using Tapatalk
thx!
can some one upload the edited app using this guide?
pedyvirus said:
can some one upload the edited app using this guide?
Click to expand...
Click to collapse
Do you mean the APK file?
If so, then that's here: https://dl.dropboxusercontent.com/u...ndroid/CloneyBirdTutorial/CloneyBirdPart8.apk
And the source code is here: https://dl.dropboxusercontent.com/u...es/basic4android/CloneyBirdTutorial/Part8.zip
Just out of interest, has anyone purchased B4A as a result of my posting and tutorial series? I'm very interested to din out what pushes people to part with money to buy software. I understand many people will look at this and say "why buy that when I can just use Eclipse for free" but it makes things easier and people will pay for that benefit.
Update: more source code for more games!
I just wanted to post a short update to this post:
I've also uploaded source code for a matching game using LibGDX and Basic4Android, it's called Orchard Crush and it's on the play store:
Get the source code here: https://dl.dropboxusercontent.com/u/8673694/OrchardCrush_public.zip
See the game here: https://play.google.com/store/apps/details?id=uk.co.coffeeinducedgames.orchardcrush
VOS said:
Just out of interest, has anyone purchased B4A as a result of my posting and tutorial series? I'm very interested to din out what pushes people to part with money to buy software. I understand many people will look at this and say "why buy that when I can just use Eclipse for free" but it makes things easier and people will pay for that benefit.
Click to expand...
Click to collapse
B4a / b4x kicks ass my friend

Categories

Resources