Skip to content

Teguh Eko Budiarto

Web Programming and Sharing Experience

Archive

Category: Python

Since Python is not a strongly typed programming language, you do not have to specify your variable type. This is nice but have some drawback for Netbeans, which it can not recognize the type easily so you can not have good suggestion for the intellisense feature. To fix that you have to specify the type of your variable and make sure you already import the correct module.

For example, when you have this kind of code (below code are for example purpose only)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from datetime import datetime
from django.db import models
from django.utils.translation import gettext_lazy as _
 
class Poll(models.Model):
    question = models.CharField(max_length=200)
    password = models.CharField(max_length=200)
    pub_date = models.DateTimeField(_('date published'), 
                          default=datetime.now)
    class Admin:
        pass
    def __str__(self):
        return self.question
    def get_choice_list(self):
        return list(self.choice_set.order_by('id'))
    def get_choice_from_num(self, choice_num):
        try:
            return self.get_choice_list()[int(choice_num)-1]
        except IndexError:
            raise Choice.DoesNotExist
 
class Choice(models.Model):
    poll = models.ForeignKey(Poll)    
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()
    class Admin:
        pass
    def __str__(self):
        return self.choice
    def get_num(self):
        try:
            return self.poll.get_choice_list().index(self)+1
        except ValueError:
            raise Choice.DoesNotExist

For people like me, usually the first thing I do when want to use a defined variable is to hit the ctrl-space button to display the Intellisense suggestion. But in this case, when I want to use functions or variables defined in the attribute poll in Choice class, it displays :
specify type netbeans python

Which means Netbeans does’nt understand the type and the intellisense just throw all the types available to you and it become garbage, instead of suggestion. To teach Netbeans the type of the variable, just click the Specify type of [the variable name] menu, and then type your variable’s type. After that the intellisense will give you nice result, like this picture below:
specified type netbeans python

Other thing is to make sure you have imported your class in your file so Netbeans will recognized it properly. Hope it helps, Cheers! :)

This tip is for windows XP user ( some other windows version will also have similar procedure).

If you are using an automatic configuration script for your internet setting, most probably, Python will not be able to connect to internet. This is troublesome if you want to install some packages which has dependencies which need to be fetched from the net. You need to change your internet options setting to use the proxy address directly.

Below is how to do that:

  • Go to Control Panel
  • Open Internet Options
  • Open Connection Tab
  • Click on LAN Settings button
  • Check the Use a proxy server for your LAN…
  • Enter the proxy IP Address and its port. If you do not know where it is, ask your network administrator or just open the configuration script to find out where is the IP you need to use.
  • Press OK until all the setting windows are closed.

Below is the screen shot of the internet options screen.

Windows XP Professional Internet Options Screen

Windows XP Professional Internet Options Screen

I wrote this post in my journey to adapt Python with Django framework as my tool in the next project. A little bit skeptical and some holding back since I had background in PHP and C# .Net. But, I have no choice because Python is already team’s decision for new projects. So, here I go with learning new language and framework again.

In the way, sometimes I can not find a distributable package for your Python version. In one case, I would like to install setuptools to install other packages, soaplib which I need to build a SOAP web service. This is because most of our legacy applications are using C# which using SOAP to interface with web services, otherwise, I prefer to create REST based web service. Anyway, this is just my beginner way of thinking.

So, enough with the mumbling, below is how it is:

  • Unpack the source into a folder.
  • Using command prompt, go to the folder and run command below ( I assume that you already set your python PATH and can run Python command from command prompt).
  • python setup.py bdist_wininst
  • Voila! An executable installer for your installed Python version will be available in dist sub folder.

Very easy isn’t it? Yeah, if it is that easy for me to find how in the first place, I would’nt write this post.