Helpful, but could use a little more: this is my first foray back into any sort of programming after two years since intro classes. Let me see if I understand this. So the first two lines of that table up there would export to CSV as something like LOPAB;plush;imp;plush LOPAB;batting;imp;cotton And the program will read through it line-by-line so it gets put into a list where the grist and name can be looked up by the land and the type of underling? What exactly are the square brackets doing? Are those analogous to slices, or? Why should that probably be a defaultDict/what exactly is a defaultDict? I'm also not getting what the exception catching thing is doing there.
That is indeed what the CSV should look like. (I only used semicolons because you have the grist names list which will need its own separator, for which I used commas). The catch is an excel export won't parse that the title belongs as the first column of each row. You'll need to do a little work to put all of this into its own sheet with the new structure. This is close: It's being added to a python dictionary which is a hash map implementation. So instead of seeking by index (list[1] to get to get the second item) you're using keys (dict[key] gets the item in the map at the hash of key). But effectively the same. Also, logic may need to be fixed based on type versus name. I didn't pay close enough attention to the table to figure out which one is more useful in that regard. Similar in that you get back an object, but in the case of an index or key access, you're getting a single thing back instead of the iterable. Specifically, the brackets are doing some magic and calling the __getitem__ function on each of the objects. But that's the implementation. So, DefaultDicts are a really cool data structure that let's you not use the try: except: block. Specifically, if you try to access a DefaultDict and the key doesn't exist, instead of getting a KeyError, you get back a new object. So a DefaultDict(dict) if you try to get a missing key, you'll get back {} which is just an empty dictionary. Which lets you do the silly double access thing without the exception handling. Short version: if you try to access a dictionary and there isn't anything there, you get a KeyError. So encounter_table[land] is trying to access the key at land. If you were trying to put something there with an assignment (encounter_table[land] = dict()) it wouldn't be a problem. That's how you add keys to dictionaries! But if instead, you try to operate on the expected return object (IE encounter_table[land][underling_name], which is get me the thing in encounter_table at the key land then give me the other_thing in that thing at key underling_name) you'll get the KeyError because nothing is there! So the handler basically goes to put data into an existing dictionary, finds out it doesn't exist, then creates it. Simple. >.>
So I have a text file that got fucked up by encoding somehow and now the only version I have has a space after every character, including spaces. Does anyone know a way I could just take every other character so the thing's actually readable via (Mac OS) command line instead of having to write a program myself?
Anyone know any good resources for someone new to java? I've got Java: a beginners guide, sixth edition, which seems good but whenever i try to run a java program, literally copied from it, it just flashes the cmd window over the screen for a fraction of a second, even though i'm fairly certain its supposed to stick around at least long enough for me to read the text its supposed to drop in cmd.
Errrr windows. Can't help you there, sorry, don't know a whole lot about Windows command line or shells, and it sounds like that's where your problem is. Didja Google your problem yet?
Add a command that tells the system to wait a bit after printing, or set it to receive input after printing. Alternatively you couldjust run it from the command line.
I don't know how to do that yet, I litterally just started learning. This is supposed to be an example program. I also don't know how to run from the command line.
-practices thread necrourgy- (update: adhd is a bitch so i started over with everything, so if at some point i said "i started learning (language)" and im repeating that now, i took a break and restarted) so im learning ruby, and up until a certain point it was kinda similar to java, except for the way it handles syntax, but now i hit the methods/blocks/procs/lambdas part and some of this shit is insane (aka got difficulties wrapping my head around the differences) now blocks are basically unnamed methods, but what's the difference between methods, procs, and lambdas? i gotta say i love the user input, collect, and times functionalities, way more beautiful than in java "_" (but i already felt myself leveling up after reading up on stuff regarding yield (even though i still dont know why you'd do that) (is it a recursivity thing so youre not actually recursive or), so, progress has been made) also, shoutout to the docent doing web programming at my institute, who is teaching us the markup & programming, but also how to use the command line we'll be confronted with if we do stuff in that direction
So procs and lambdas are objects that happen to revolve around doing a bunch of stuff, while a method is the actual doing of a bunch of stuff. In particular, procs and lambdas have methods and can be manipulated by or passed to methods. You can also shove them into arrays and such. The difference between procs and lambdas is kind of subtle, so I'll let this guy explain. Note that that page is a bit old; I don't know if the exact behavior has been changed in later versions of Ruby.
It's a bit more powerful than a function pointer, since it can do things like read off how many arguments the function is supposed to take and store internal attributes and compare two functions, whereas from what I can tell a function pointer can really only reference a piece of code.
Pretty sure Ruby and Python use blocks in the same sense, which specifically means "a self contained section of code." So in python, a class definition is a block (All the indented code), as is everything under an if statement, inside of a loop, inside of a function. Then Python and Ruby Lambdas are the same: Anonymous functions. Procs isn't a thing I know, so can't help there. And I didn't know Ruby had Yield, but if it's anything like Python, it's for allowing a function to return a value, but be able to be called again from the point it's at. In python we use them to make generators, which can output a series of values, one at a time.
A function pointer is partially defined by its arguments, so....? Yeah, kind of like... an ovject function pointer I guess. Though I think you might be able to replicate a lot of the functionality of that with, say, static function-scope variables.
Please forgive me if this has been covered, but I didn't want to read the whole thread before asking. My dad got an IBM PC in '81 when I was six, and I learned MS BASIC, BASICA, Qbasic, Quickbasic, and dabbled in Visual Basic. What I loved about it was the ability to get instant results; you could write one or two lines of code and draw something on the screen. Then you could add to it and make more things happen. My best program was a space-war thing with up to five teams of manual and AI ships, and several types of ships each with two unique weapons. (Yes, it was strongly Star Control inspired.) That was about 20 years ago. Now I want to get back into recreational programming, making games and simulators, and from what I hear the way to go is C++ or something like it. I also want to be able to use video card functions. So, is C++ really what I want to learn? What compiler? What environment? How do I get started? It's all so much more complicated than it used to be.
The problem with C++ is that it is pretty much the opposite from instant results you could possibly want. I'm not in any way a games programmer, but I know a lot of hobbyist game programming these days is in things like python? I think a few people here are doing things like that. I'm pretty much only a server-side or command-line coder so nothing to help you with there, alas.
You probably want something like Python if you're starting out. C++ is great for making things robust and controlling resource usage, which is important for triple-A games, but I find it a real hassle to use if you want results to come fast since you need to pay attention to so many aspects other than just getting the program to do a thing. Python has a lot of built-in stuff for making programs quickly. Think cake-mix versus making batter from scratch. Python is cake-mix and comes with frosting and stuff readily available. Then once you're comfortable with that you can learn C++ and learn to handle memory stuff and pointer arithmetic. On the other hand it does use indentation for syntax, which is awful. A similar language is Ruby, which has the nice feature of using brackets to bracket things, rather than spacing.