Python resistor program

I heard a couple of people discussing Python on Wednesday. I know a bit, although not very much. Would be happy to share what I do as I go along, and would welcome comments from those more experienced? Is it possible/sensible to have a group on here for Python?

To start with, I’m also trying to learn about electronics. I’m writing a program that takes a list of resisitor values (I bought a mixed pack online ages ago) and a given value and works out how to create the given value by combining them in series/parallel. That’s a work in progress but I’ve written this function, which formats resistor values nicely:

ohms = "\u03A9" #UNICODE for omega sign
prefixes = {0:"",3:"k",6:"M"} #dictionary for SI prefixes

def FormatResistance(value):
    x = math.log10(value)          #get order of magnitude
    x = x - (x % 3)                #restrict it to SI groups of 3
    prefix = prefixes[int(x)]      #look up prexix
    final = int(value/(10**x))     #get value in new units
    return(str(final)+prefix+ohms) #format with new unit

I always feel the worst thing about Python is that I’ve never found a good environment in which to develop it. Have you found anything fun to help with writing the code?

Hi @WetEmoFish I haven’t really done anything huge in it so have been using Geany which is a fairly standard I think programming editor. It does let you collapse functions classes etc on the display and does code completion and stuff.

That looks quite smart. On the mac I have Coderunner. But it gets awfully confused when distinguishing between Python 2.7 and 3.

I haven’t had too much trouble with python 2.7 and 3, but I’ve written everything in 3 and haven’t really edited anything in 2.7. The print() statement seems to be the biggest issue for me!

Not used it for Python (yet) but I swear by atom for my code editing needs.

There are some really useful plugins out there and the git integration is second to none!

Git is something I think I’ll have to learn to use one day!

1 Like

It’s an amazing tool, it really is. It’s incredible to think that Mr Torvalds whipped up version 1.0 over a weekend.

Good selection of information about it here:

That is a really useful site, thanks @treb0r! I’ll have another look when I get chance, am at work now.

Makes me want to do a project to the point where I need version control!

actually maybe it would make more sense to start using it on a smaller project, to understand it!

It’s worth knowing that bitbucket will give you unlimited free private repos to use for anything you want.

Get an account and start a repo. You can then easily sync stuff from your desktop machine.

that’s a handy tip - can I do repositories on my own server on local network too?

Yes, this is one of the core features of Git that makes it better than other revision control systems: it is completely decentralised. You can create repositories on your local machine and then push and pull changes between them and other, remote repos.

If you want to run your own standalone git server there is a very cool tool called Gitlab. This is basically your own bitbucket or github. It can be installed on any Linux machine and has a really nice GUI. A lot of people set it up to automatically pull changes from their Bitbucket or Github accounts so they have a fallback should something happen.

Thanks @treb0r I will check it out.

This could be a use for a bridge rectifier server if we want to develop any code together?

Making a home server from old computers is prob the first hacking/making thing that I did and it’s been really useful!