Author |
Message |
neufelni
|
Posted: Mon Oct 16, 2006 9:55 pm Post subject: Crimson Editor output help needed |
|
|
Does anyone else here use Crimson Editor. If so, I need some help with it. For some reason it will not output anything until I have given it all the input. So for a program like this:
Ruby: | print ("Enter your name: ")
name = gets()
puts("Hello #{name}")
|
The output is blank until I enter name and then it puts:
Quote: Enter your name: Hello Nick
Even for long programs that require alot of input and also output alot, I have to give the program all the input that it uses throughout the program before it will output anything.
It is only doing this for Python and Ruby code. It works fine if I use C++ or Java. Does anyone know why it is doing this?[/quote] |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
wtd
|
Posted: Mon Oct 16, 2006 10:24 pm Post subject: (No subject) |
|
|
It may well have to do with how buffering is handled. Many environments use line buffering, where output is only printed when a newline is printed.
You can compensate for this by explicitly flushing standard output.
Oh, and your use of parens is a bit excessive.
code: | print "Enter your name: "
name = gets
puts "Hello #{name}" |
|
|
|
|
|
![](images/spacer.gif) |
neufelni
|
Posted: Mon Oct 16, 2006 11:02 pm Post subject: (No subject) |
|
|
Quote: It may well have to do with how buffering is handled. Many environments use line buffering, where output is only printed when a newline is printed.
You can compensate for this by explicitly flushing standard output.
How would I do that? I tried adding puts "\n" before I get my input but it still does the same thing.
And also, if I have a long loop in Python that goes through a bunch of numbers, makes some calculations and then outputs the result, the program won't output anything for about 10seconds and then it will ouptut a lot of the numbers at one time and then stops, wait a bit longer again before it outputs more numbers. If I write the same program in Java it just continually goes through all the numbers. Why would it only do stuff like this with Python and Ruby and not Java or C++? Also, if I use a different IDE like IDLE for Python I don't have this problem.
Quote: Oh, and your use of parens is a bit excessive. Smile
code: |
print "Enter your name: "
name = gets
puts "Hello #{name}" |
I just started learning Ruby today and the tutorial that I used suggested that I should use brackets because it is clearer and Ruby is increasingly moving towards the use of brackets. |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Mon Oct 16, 2006 11:20 pm Post subject: (No subject) |
|
|
Nick wrote: Quote: It may well have to do with how buffering is handled. Many environments use line buffering, where output is only printed when a newline is printed.
You can compensate for this by explicitly flushing standard output.
How would I do that?
I can't speak for Crimson Editor, but flushing the output channel is done with:
Nick wrote: Quote: Oh, and your use of parens is a bit excessive.
code: |
print "Enter your name: "
name = gets
puts "Hello #{name}" |
I just started learning Ruby today and the tutorial that I used suggested that I should use brackets because it is clearer and Ruby is increasingly moving towards the use of brackets.
A tip: getting the terminology right is important. Parentheses, brackets and braces are all different things.
And generally it is important to use parens primarily for disambiguation. There is nothing ambiguous about your code. ![Wink Wink](http://compsci.ca/v3/images/smiles/icon_wink.gif) |
|
|
|
|
![](images/spacer.gif) |
rdrake
![](http://compsci.ca/v3/uploads/user_avatars/113417932472fc6c9cd916.png)
|
Posted: Mon Oct 16, 2006 11:23 pm Post subject: (No subject) |
|
|
Nick wrote: Quote: It may well have to do with how buffering is handled. Many environments use line buffering, where output is only printed when a newline is printed.
You can compensate for this by explicitly flushing standard output.
How would I do that? I tried adding puts "\n" before I get my input but it still does the same thing. Quite unnecessary. If you're using the printf method, then a newline must be inserted. Puts does this for us, "put string" .
code: | # The following should output the same thing
puts "Hello, world!"
printf "Hello, world!\n" |
|
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Mon Oct 16, 2006 11:26 pm Post subject: (No subject) |
|
|
In the spirit of expressing this in two lines...
code: | print "Enter your name: "
puts "Hello #{gets}" |
|
|
|
|
|
![](images/spacer.gif) |
neufelni
|
Posted: Tue Oct 17, 2006 5:44 pm Post subject: (No subject) |
|
|
I haven't figured this out yet. However there was someone on the forum at the Crimson Editor website who had the same problem as me, only with Perl. He was told to put this line at the beginning of his program.
What does this do and how would I do it in Python and Ruby?
I have been thinking about just getting a different editor. What would you suggest is a good one. I want one that is free and supports multiple languages. |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Tue Oct 17, 2006 6:13 pm Post subject: (No subject) |
|
|
Crimson Editor is good if you ask me, it's what I use for the majority of any programming. For Ruby, why not just do things the 'normal' way; edit the code in the editor and run it from the command line? Crimson Editor is not an IDE, contrary to what many people believe, it is simply an editor with shortcuts/macros. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
wtd
|
Posted: Tue Oct 17, 2006 6:20 pm Post subject: (No subject) |
|
|
Nick wrote: I haven't figured this out yet. However there was someone on the forum at the Crimson Editor website who had the same problem as me, only with Perl. He was told to put this line at the beginning of his program.
What does this do and how would I do it in Python and Ruby?
http://www.kichwa.com/quik_ref/spec_variables.html
I am not certain that either Python or Ruby have this particular fucntionality. There the more appropriate approach would be to flush individual IO objects. |
|
|
|
|
![](images/spacer.gif) |
|