So I was wondering if someone could answer me a couple of questions regarding the pickle module:
Is there any threading involved when it loads/dumps?
does it return after it is completely done in pickle.dump()?
I have some code that is like this:
f=open(filename, 'wb')
pickle.dump)((my_dict, f, 2)
f.close()
But when I open the file it is human readable. According to the docs, protocol 2 is bytes, does that not mean it should not be human-readable?
These are probably really newbie questions but I appreciate your answers in this matter.
Related
Is it possible to take this line of code:
Code:
Browser("site").Page("site").WebElement("xpath:= ((//*[contains(text(), 'Login')]))[1]").HighLight
And do something like this:
Code:
WebLink = Browser("site").Page("site")
WebLink.WebElement("xpath:= ((//*[contains(text(), 'Login')]))[1]").HighLight
I think in terms of readability where you have a TON of code, this would read much better. You only have to declare this once and call the variable.
Unless there is a better way I just haven't thought of.
I actually found a link explaining how to solve my scenario shortly after posting the question, but decided to leave it open simply for the way the question is phrased for future newbies..
Link:
Buildup and reference of objects in HP UFT
This lead me to the below solution:
Code:
Set WebLink = Browser("site").Page("site")
WebLink.WebElement("xpath:= ((//*[contains(text(), 'Login')]))[1]").HighLight
So I'm brand new to Go, I am moving over from python b/c of concurrecny.
Anyways I was looking at the net/http package documentation and stumbled upon this:
client := &http.Client{
CheckRedirect: redirectPolicyFunc
}
So I see we are creating a client variable by referencing the original Client structure (I think that is how you would word that) but I am totally lost at the
CheckRedirect: redirectPolicyFunc
What the heck does the ":" mean and what are we doing with it? Also what are the things before and after it? I read the struct documentation and did the introduction to go tutorial but I didn't see anything, I may not of been looking hard enough. No doubt its simple I just have no idea where to start looking for answers.
Thanks for the answers everyone! This makes much more sense now!
This is called a composite literal.
You're just creating an instance of the http.Client type and setting the
CheckRedirect property, then taking a pointer of it.
I had another question about processing and a project i'm making. I would like to play a movie in a loop on the background. I managed to do this by initializing a Movie and putting it in an image the size of my app. But now I would like to load in multiple movies and add a button to change the background when pressed with the leap motion. Is this possible ? Or should I use a different library for this ?
Thanks in advance!
Kind regards,
DarthSwedo
It's really hard to answer general "how do I do this" type questions. Stack Overflow is designed more for specific "I tried X, expected Y, but got Z instead" type questions. You'll have much better luck if you just try something and post an MCVE if you get stuck.
That being said, I'm going to try to clear up some of the general confusion you seem to have.
Step 1: You need to figure out what library or libraries you're using. In all of your questions, you seem to not be sure which library you're using. Which Leap Motion library are you using? How did you set it up? Where is its documentation? You say you're using a Movie class. Where is that coming from? Are you sure it's not from the Video library?
If you have more specific questions in the future, please provide this information. We can't really help you without it. But more importantly, you need to know the answers to these questions if any of this is ever going to make any sense.
Step 2: Read the documentation for those libraries. Processing comes with the reference. The Video library comes with its own documentation page. I'm sure whatever Leap Motion library you're using has something similar. You need to read about the functions available to you. That's a huge part of programming. Right now your question is just asking whether something possible, and the honest answer to that is, well, what happened when you googled it?
Step 3: Try something. After you read through the documentation, just try something. Write some code based on the examples in the documentation. Even if that code doesn't work, that's okay, because then you can use it as an MCVE and ask a more specific question.
Good luck.
First of all, in this question I'd like to stay away from the polemic on whether source code commenting is good or bad. I'm just trying to understand more clearly what people mean when they talk about comments that tell you WHY, WHAT or HOW.
We often see guidelines like "Comments should tell you WHY; code itself should tell you HOW". It is easy to agree with the statement on an abstract level. However, people usually drop this like a dogma, and leave the room without further explanation. I've seen this used in so many different places and contexts, that it looks like people can agree on the catchphrase, but they seem to be talking about different things entirely.
So, back to the question: if comments should tell you WHY, what is this WHY we are talking about? Is this the reason why that piece of code exists in the first place? Is this what that piece code should be doing? I would really appreciate if someone could give a clear explanation, and then add some good examples (bad examples are not really needed, but fell free to add them for contrast).
Please do not immediately close this question as duplicate or polemic. I have tried hard to make it very objective. There are many questions on whether comments are good or bad, but no one that addresses the specific question of what are good examples of comments that tell you WHY.
Thanks,
Comments serve two main purposes:
to summarise. Many would say "why document this method when we can just read the code?", but one line of text that describes what a method is for/what it does, can often be much faster to read and easier to understand than 30 lines of code, especially if that code calls other methods that you may need to read as well...
to explain the things that are not obvious from the code - the WHY, or more detail on the how. Simple examples include "we must add the new XmlElement and then remove the old one, as the ReplaceChild method in .net does not work!", or "Uses an iterative Newton-Raphson approach to solve for X ", or "we must not close the port here because the reading thread may still be running", or "use this method where performance is critical, but beware that this method may provide a result that is in error by up to 5%"
Hai guys,
I ve seen people including comments in their program..
Is it to improve inter-programmer communication
and code readability, by explicitly specifying programmers’
intentions and assumptions?
Should comments be in technical terms rather than in natural launguage terms?
How to use comments as effective as possible?
Is it really a good practice adding comments to a program?
Comments should only be used to explain why the code is the way it is. It should never explain what the code is doing. What the code is doing is described by the code.
That being said, some languages have tools that look for special characters in the comments in order to generate documentation. Java is one such language. But these aren't so much code comments as they are documentation that happens to use the same syntax as language comments.
Comments can be used for auto-documentation, communication amongst other developers, memory, todo lists, or basic explanations of functionality. Note that comments ought to be supplementary - if your code needs comments, you need to reconsider your code.
To be as effective as possible, work out a template for your comments to exist in. Again, this will not only help you read and understand your code, but it may help a parser create documentation for you from your comments if they're in a consistent format throughout the code.
Writing clear code is always the first step to making your code easy to understand. You can then explain parts that are not clear by looking at the code, in comments.
For myself, comments explain what I was thinking at the time. That way, six months from now when I don't remember what I was writing, I can use the comments to understand.
Some classic uses of comments:
Explaining why code wasn't done in the most obvious way -- Such as interfacing with systems that use weird or old ways to talk.
Explaining what code might call this code -- Such as in large and complicated system. You can add examples showing code that might need to call this.
Documenting exceptions to current coding practice -- Such as legacy code that hasn't been refactored to use the current systems.
As a rule, if you ever find yourself doing something non-obvious, comment it.
An alternative way of commenting is to start by writing the body of a function as comments. Then break the comments apart and put the code underneath. When it finally works, cleanup and fix the comments.
Ciao!
I try and comment each function describing at a high level, but precise way, what the function does. The precision should be such that it is not necessary to read the body of the function to understand what the function does, or to re-implement it and have it work perfectly with any code that calls it.
Other than that, I try and keep functions small enough that the above is basically all the necessary documentation.
Once in a while, there may be something obscure or odd in what is being done in the code - I document that. Anything that isn't obvious or intuitively right, or that you spent some time thinking about, should be documented.
Just imagine you have a memory problem and will forget writing this program in a month. Then imagine you have to go back and fix it. What would you like commented and how could those comments be made most useful to you?
it's better to make the program self-describing, then no much comments are needed.
First try to write code so people can follow without comments.