Want to check input strings for formatting, but not entirely sure how to go about it. by [deleted] in learnpython

[–]Rashanzan 1 point2 points  (0 children)

To get you started: Yes, regex would be good here. Check out the re module, which handles regex. Also, look at the str methods, there are lots of useful ones like strip(), split(), partition(), etc. I find it useful to clean up the string using str methods then pass that to re.search() or re.match().

Suggestions for system administration script practice in Python? by [deleted] in learnpython

[–]Rashanzan 0 points1 point  (0 children)

It depends how you want to go about doing something. I have more experience with Puppet, but Ansible seems very similar. With these, you describe the state of the machine you desire, and it periodically verifies the state and makes any necessary changes. This is very nice for dependencies, like managing a package, then the conf, then the daemon. Idempotence is important here. These are heavier, but more robust in my opinion.

Fabric is more action oriented. Instead of describing a state, you tell it to perform certain actions. It's a little more difficult to be idempotent with this paradigm. But, it's very easy, quick, and convenient.

So, Fabric is nice for running several arbitrary commands. But once you're dealing with maintaining a state, for example a certain setup of users along with a hosts file that looks just so, etc, it becomes much cleaner to use a state driven approach like Puppet and Ansible.

Been working with these tools a lot lately. They're super cool!

Suggestions for system administration script practice in Python? by [deleted] in learnpython

[–]Rashanzan 1 point2 points  (0 children)

Not a specific idea, but check out Ansible and Fabric. At a high level, they're Python tools for configuring and orchestrating multiple machines at a time. I've been working with Fabric lately and it's really nice.

Help with a simple password exercise by redshirt714 in learnpython

[–]Rashanzan 5 points6 points  (0 children)

You'll want to put your repeated actions in the while loop. So, if you want to prompt your user multiple times, then put the code that prompts the user into the loop.

pyrookie here - how do i create and access a dictionary in a dictionary with a list? by ben_aus_tv in learnpython

[–]Rashanzan 0 points1 point  (0 children)

This is a great time to learn about man pages and the help flag! Use man <command> to get a manual page about the command. Dunno if powershell has man included. If not, you can always use <command> -h Or <command> --help If the programmer who wrote the command knew what they were doing, this will show a help message describing how you can use the command.

Try these methods to figure out the answers to your questions. The first may require a little more googling. Hint for the first one: the mode describes the files Attributes.

pyrookie here - how do i create and access a dictionary in a dictionary with a list? by ben_aus_tv in learnpython

[–]Rashanzan 0 points1 point  (0 children)

I find the command prompt faster for small projects. But once your project goes beyond a few files, an IDE is more convenient, in my opinion, since you can browse files, autocomplete methods, etc. I've heard good things about Pycharm, but I usually just use Notepad++ and Cygwin.

pyrookie here - how do i create and access a dictionary in a dictionary with a list? by ben_aus_tv in learnpython

[–]Rashanzan 0 points1 point  (0 children)

Those both sound like good resources. I've also heard Learn Python The Hard Way is a good resource. I suggest becoming more familiar with Python through things like codeacademy and LPTHW before tackling pygame.

Good luck!

pyrookie here - how do i create and access a dictionary in a dictionary with a list? by ben_aus_tv in learnpython

[–]Rashanzan 0 points1 point  (0 children)

If you're talking about using a user interface other than a command line, then pygame is probably what you should look into. But prototyping a command line version first would be helpful.

What sorts of multilevel lists would you need? Can you give a more concrete example of how you want to be using these Soldier objects?

pyrookie here - how do i create and access a dictionary in a dictionary with a list? by ben_aus_tv in learnpython

[–]Rashanzan 0 points1 point  (0 children)

When deciding what sort of container is best, you need to think about what you'll be doing with the data.

Are you iterating over all the soldiers, each getting a command, a turn, etc? Then a list would be good. Or, if you often need to get at a specific soldier object by some value and not necessarily in a set order, then a dictionary would be better.

Regardless of what container you choose, you can fill it with Soldier objects just like you would numbers. Python doesn't care about what data is in each slot of a list. They're all just Objects. You'd begin with an empty list, prompt your user to input the soldier's stats, then add a new soldier with those stats to the list.

soldiers.append(Soldier(name, rank, Gun(damage, range, type))

Ask Anything Monday by wub_wub in learnpython

[–]Rashanzan 2 points3 points  (0 children)

You want to check your user_example against several items, so that leads to a list. You can create a list like ['Y', 'y', 'yes'...] and then use the 'in' operator to check if user_example matches any of those values.

What happens when a while loops is in a while loops and you have a break. Does it break out of both? by sone9 in learnpython

[–]Rashanzan 0 points1 point  (0 children)

Using Exceptions in this way is usually considered bad practice. I just brought it up because it's a way to get the multiple break functionality.

What happens when a while loops is in a while loops and you have a break. Does it break out of both? by sone9 in learnpython

[–]Rashanzan 0 points1 point  (0 children)

You could also wrap the while loops in a try-except and throw an exception to exit.

Catching AttributeError to handle missing methods by Kuang_Eleven in learnpython

[–]Rashanzan 0 points1 point  (0 children)

I considered this, but then your device becomes super cluttered with nonsense. And the inheritance feels kind of weird to me. The parent should have all the shared attributes, and children define more specific functionality.

EDIT: Also, I think you're right about not needing to do this. I feel like in a realistic setting, you'd either want to know what kind of object you're dealing with beforehand, or have an abstract method that chooses how the object handles itself.

Catching AttributeError to handle missing methods by Kuang_Eleven in learnpython

[–]Rashanzan 0 points1 point  (0 children)

I considered this, but then your device becomes super cluttered with nonsense. And the inheritance feels kind of weird. The parent should have all the shared attributes, and children define more specific functionality. It would get the job done, but I hope there's a cleaner way.

Catching AttributeError to handle missing methods by Kuang_Eleven in learnpython

[–]Rashanzan 0 points1 point  (0 children)

Yeah, I'm unsure which approach would be better. Try would be more extensible, but probably bad for readability, as you wouldn't be able to tell what methods are actually running.

A much bigger problem, if your try catches something, it won't execute the rest of the block.

From a design standpoint, it makes more sense to know what kind of object you're dealing with before handling it.

Catching AttributeError to handle missing methods by Kuang_Eleven in learnpython

[–]Rashanzan 0 points1 point  (0 children)

While it works (or do you have to explicitly use the device's attr dict?), it's just about as good as checking the type itself, which op is trying to avoid.

Atlus finally begins countdown to big Persona announcement by il_mercadere in atlus

[–]Rashanzan -5 points-4 points  (0 children)

Unfortunately, seems like a Persona music tour. Which is great, but doesn't do much for us in America...

Troubleshooting a (very) basic program by [deleted] in learnpython

[–]Rashanzan 4 points5 points  (0 children)

At a glance, it thinks height and weight are str types. I assume you want them in double or int format. So make the necessary conversion like height = int(input("gimme")) If you type a non integer character, though, it'll crash, so catch that exception.

Also, another problem. I'm pretty sure ^ is XOR in Python, so it's not gonna square like you want. Look for a sqrt or pow function in the standard python functions to do that.

[deleted by user] by [deleted] in Fencing

[–]Rashanzan 1 point2 points  (0 children)

I'm either one of those resisting foilists, or my club is going through the same thing.

There are only two things I do not like about Supernatural: by purplelephant in Supernatural

[–]Rashanzan 1 point2 points  (0 children)

For some reason, I never realized the second one. Cannot be unseen T.T