Re: [Tutor] Notepad++ question
On 07/06/12 05:29, Alexander Quest wrote: Hey all; my question is regarding editing Python code in Notepad++. When I run this piece of code in Notepad++: def fix_start(s): var1 = s[0] var2 = "*" var3 = s.replace(var1, var2) return var3 I get an indentation error, which reads: File "C:\google-python-exercises\google-python-exercises\basic>string1.py line 56 var2 = "*" ^ IndentationError: unexpected indent The thing is that in Notepad++, that code does not appear with an indentation where var2 is. It appears like this: This is almost certainly down to mixing tabs and spaces. You can mix them in a file but not within a block. (And even then I would recommend sticking to just one style) Some editors make it worse by autoindenting with a mixture of tabs and spaces which is fine for C or Java but no good for Python... I don't know Notepad++ so can't comment on it. is here? Also, I am wondering why use Notepad++ or other such programs when IDLE seems to be fine for writing code. Thanks. IDLE is fine for beginners. It is less powerful than other text editors such as vim or emacs or Eclipse or even Scite. But that power is mainly useful when dealing with multi-file projects or large files. But IDLE is fine for most Python tasks. If you are happy with IDLE use IDLE. Some of the missing features that I like are: - incremental search - navigate to a character (t or f) - rectangular cut n paste - split screens vertically - integration with the OS - goto-function definition - macros But editor choice is very personal, some like a simple editor some like all the bells and whistles possible. It's up to you. Find one 9or several!) that you like and use it. But don't let choosing an editor get in the way of learning Python, they are two separate things. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Notepad++ question
On Thu, Jun 7, 2012 at 12:41 AM, Alan Gauld wrote: > This is almost certainly down to mixing tabs and spaces. > You can mix them in a file but not within a block. (And > even then I would recommend sticking to just one style) > Some editors make it worse by autoindenting with a mixture > of tabs and spaces which is fine for C or Java but no > good for Python... I don't know Notepad++ so can't comment > on it. > > In Notepad++, select Settings/Preferences. There's a tab called "Language Menu/Tab Settings" (they've put the two things on one tab to save space; the tab settings are on the right side.) You'll find a setting for "Tab size"; the default is 4 - and also a checkbox for "Replace by space", which is NOT checked by default. If you're going to be writing Python in Notepad++, you should _definitely_ check that box. Click "Close", and off you go! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Notepad++ question
Hi, as a Python beginner myself, I started out using Geany IDE. It was pretty cool editor but it caused me indentation hell! Since then I have moved to eclipse with the pydev plugin and found it much friendlier when dealing with indentation problems. But each to there own! Notepad!! is a sweet editor, I wish there was a linux version but I can't recommend Eclipse enough for beginners. Regards, Jon. On Thu, Jun 7, 2012 at 5:52 PM, Marc Tompkins wrote: > On Thu, Jun 7, 2012 at 12:41 AM, Alan Gauld wrote: > >> This is almost certainly down to mixing tabs and spaces. >> You can mix them in a file but not within a block. (And >> even then I would recommend sticking to just one style) >> Some editors make it worse by autoindenting with a mixture >> of tabs and spaces which is fine for C or Java but no >> good for Python... I don't know Notepad++ so can't comment >> on it. >> >> > In Notepad++, select Settings/Preferences. > There's a tab called "Language Menu/Tab Settings" (they've put the two > things on one tab to save space; the tab settings are on the right side.) > You'll find a setting for "Tab size"; the default is 4 - and also a > checkbox for "Replace by space", which is NOT checked by default. If > you're going to be writing Python in Notepad++, you should _definitely_ > check that box. > Click "Close", and off you go! > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 100, Issue 22
Dear All, credativ India specialized in open source, conducting a two days course on Python Programming on 27th and 28th June 2012. Interested candidates can contact: train...@credativ.in Regards, Vijayakala ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Notepad++ question
I don't use notepad or notepad++, so I don't know the settings. However, if you're familiar with vi/vim, you can download the CLI from www.vim.org for almost any flavor OS and it works quite well on Windows. BTW: you can customize your settings to use spaces instead of tabs, among others, which is usually a source of these types of indentation errors. On Wed, Jun 6, 2012 at 11:29 PM, Alexander Quest wrote: > Hey all; my question is regarding editing Python code in Notepad++. When I > run this piece of code in Notepad++: > > def fix_start(s): > var1 = s[0] > var2 = "*" > var3 = s.replace(var1, var2) > > return var3 > > > I get an indentation error, which reads: > > > File "C:\google-python-exercises\google-python-exercises\basic>string1.py > line 56 > var2 = "*" > ^ > IndentationError: unexpected indent > > > The thing is that in Notepad++, that code does not appear with an > indentation where var2 is. It appears like this: > > def fix_start(s): > var1 = s[0] > var2 = "*" > var3 = s.replace(var1, var2) > > return var3 > > but when I copy and paste it, it pastes with an indentation where var2 is, > which is what I think is causing the error. The code runs fine if I just > use IDLE. I am doing Google's python exercises, and they recommended I edit > the settings on Notepad++ to indent 2 spaces upon a tab, this being the > convention at Google. Does anyone know what the deal is here? Also, I am > wondering why use Notepad++ or other such programs when IDLE seems to be > fine for writing code. Thanks. > > -Alex > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Notepad++ question
Marc Tompkins wrote on 07 June 2012 at 08:53:- > In Notepad++, select Settings/Preferences. > There's a tab called "Language Menu/Tab Settings" (they've put the two things > on > one tab to save space; the tab settings are on the right side.) You'll find a > setting for "Tab size"; the default is 4 - and also a checkbox for "Replace > by space", > which is NOT checked by default. If you're going to be writing Python in > Notepad++, > you should _definitely_ check that box. > Click "Close", and off you go! There is also an option to make tab characters and space characters visible. In the 'View' menu, select 'Show Symbol' and then make sure the 'Show White Space and TAB' option is ticked. That makes it very easy to see where tabs and spaces are being used. -- Michael This mail was sent via Mail-SeCure System. This footnote confirms that this email message has been scanned by PineApp Mail-SeCure for the presence of malicious code, vandals & computer viruses. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] special attributes naming confusion
On 6/6/2012 4:28 PM Steven D'Aprano said... Prasad, Ramit wrote: That is, for loops first try to build an iterator by calling __iter__, and if that fails they try the sequence protocol obj[0], obj[1], obj[2], ... So...I could instead write __getitem__ for the same effect? Er, no... __getitem__ and __iter__ do very different things. __getitem__ returns individual items, and __iter__ returns an iterator object which, when passed to the next() builtin, returns the next item. I'd say it depends on what you need when you say for the same effect. This is the same effect for some definition thereof: class Iterable: def __init__(self,count): self.maxitems=count def result(self,idx): return idx**idx def __getitem__(self,idx): if idxhttp://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] special attributes naming confusion
> >> That is, for loops first try to build an iterator by calling __iter__, and > if > >> that fails they try the sequence protocol obj[0], obj[1], obj[2], ... > > > > So...I could instead write __getitem__ for the same effect? > > > Er, no... __getitem__ and __iter__ do very different things. __getitem__ > returns individual items, and __iter__ returns an iterator object which, when > passed to the next() builtin, returns the next item. > > I trust you aren't calling __iter__ explicitly! Always call it from the > built-in function iter(), or better still, don't call it at all and let the > for loop do so. > I never call __iter__ and rarely call iter; usually I just let Python handle all that. > For the record, here is pseudo-code emulating how Python for-loops work. > "for x in obj: do_something(x)" becomes something similar to this: > > try: > # Try the iterator protocol first. > it = iter(x) > except TypeError: > # Fall back on the old-fashioned sequence protocol. > counter = 0 > while True: > try: > x = obj[counter] Does this access not use __getitem__()? Not that I would ever use this in reality, but it is interesting to note. > except IndexError: > # We must be past the end of the sequence. > del counter > break > do_something(x) > counter += 1 > else: > # Iterator protocol. > while True: > try: > x = next(it) > except StopIteration: > # We're done. > del it > break > do_something(x) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Notepad++ question
On 06/07/2012 02:36 PM, Alexander Quest wrote: > Ok, thanks guys. I also had one more quick question regarding a piece of > boilerplate code: > To get a response, you will needs to leave your question at the python tutor newsgroup. We are part of a group, not offering private advice. Normally, you just do a Reply-all to one of the existing messages on the thread, to include the group. But you can also typetutor@python.org as a CC: I've been volunteering my time on various forums for over 25 years now, so I think I speak for lots of other volunteers. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor