Etiket: python

  • Python’da Yield Kullanımı

    Giriş:

    Python’da yield, return’e benzer bir şekilde çalışır. Herhangi bir programlama dilinde olduğu gibi, çalıştırılan bir metodun sonucunu döndürmek için return ifadesini kullanırız. Return ifadesi yalnızca metodun ürettiği değeri döndürür, Yield ise, çoklu sonuç içinden bir değer döndürüp bulunduğu noktayı hatırlayarak, sonraki çağrıda bulunduğu noktadan sonraki değeri döndürür. Return yerine python’da yield kullanılan fonksiyonlara generator fonksiyon denir ve birden fazla yield ifadesi barındırabilir. Bu şekilde bir fonksiyonun birden fazla sonuç döndürmesi sağlanabilir.

    (daha&helliip;)
  • HTML dosyalar için img etiketine açıklama ekleyici

    html Eğer bir framework kullanmıyorsanız HTML ile uğraşmak çok zaman kaybettirici bir iş haline gelebiliyor. Her sayfaya aynı etiketleri yerleştirmek, her sayfanın menülerinin aynı olduğundan emin olmak. Anahtar kelimelerin <img> etiketlerine yerleştirmek vb.

    Benim için en acı verici kısım son yazdığım kısım. SEO adına her <img> etiketine bir “alt” değeri eklemek gerekiyor ve bu değerlerinin her birinin farklı bir anahtar kelime olması önem taşıyor. Zaman içinde bir çok kere bu sorun ile karşılaştım. Yakın zamanda da karşılaştığım bu sorunu hem şimdi hem de ileride daha kolay çözebilmek için sonunda oturdum ve basit bir “python script”i yazdım.

    Amaç HTML içerikte bulunan <img> etiketlerindeki boş “alt” açıklamalarını, verilecek bir anahtar kelime dosyası python_sh-600x600içeriğindeki kelimeler ile rastgele doldurmak. Bu amaç doğrultusunda “aalaras” (Automatic Alt Argument Assigner) projesi oluştu. Bu gün içinde yazıp bitirdiğim proje umarım HTML dokumakla meşgul olan bir çok insanın yardımına koşar.

    Projeye ulaşmak için soldaki menüden ya da buraya tıklayarak Github depoma ulaşabilirsiniz. Scriptin kullanımı hakkındaki bilgi proje deposundaki “README.md” dosyasında bulunmaktadır.

  • Installing Django-CMS over Python Virtual Environment on Ubuntu based systems

    Prepare for virtual environment:

    $ sudo apt-get install python-setuptools python-dev build-essential
    $ sudo easy_install pip
    $ sudo pip install virtualenv

    Creating a virtual environment:

    $ virtualenv example_env -p python2.7 –no-site-packages –distribute

    Activating virtual environment:

    $ source example_env/bin/active

    Installing Django and Django-CMS in to virtual environment:

    $ pip install PIL
    $ pip install django-cms

    the command above is also installs those required packages:

    django
    django-mptt
    django-classy-tags
    django-sekizai
    south
    html5lib

    Thats all. Library installation on virtual environment is complete. On the next, how to run django-cms on django with apache…

     

    Note: If you want to exit from virtual environment just type this:

    $ deactivate

  • Installing 64Bit Python, iPython environment to Windows Server 2008

    Download latest python installer in to windows server 2008 and install it.
    Download http://peak.telecommunity.com/dist/ez_setup.py from setuptools (http://pypi.python.org/pypi/setuptools) and run with python

    python ez_setup.py

    And after all download ipython source for windows environment (http://archive.ipython.org/release/0.11/ipython-0.11.zip) Extract it and install by the command below:

    python setup.py install

    Thats all….

  • PyCharm & Linux FS Notifier

    Native file system watcher for Linux

    If you’re an IntelliJ user working under Linux you’ve probably seen that boring “Synchronizing files…” spinning icon in a left corner of a status bar. It is there because for an intelligent IDE it is a must to be in the know about any external changes in files it working with – e.g. changes made by VCS, or build tools, or code generators etc. On Windows and Mac OS X native file system watchers used to facilitate this task but on Linux the only option was to recursively scan directory tree. Now you’re welcome to give a try to native file system watcher for Linux.
    Prerequisites
    File system watcher requires inotify(7) facility. It is in mainstream kernel for more than two years (since 2.6.13, and in glibc since 2.4) so chances are your distribution don’t missing it. The sign of inotify availability in a system is a presence of /proc/sys/fs/inotify/ directory.
    Download and setup
    File system watcher is a single binary executable (fsnotifier) and can be downloaded directly from our Git repository. It should be named ‘fsnotifier’, placed into bin/ directory of your IDE and granted execution rights. Inotify requires a “watch handle” to be set for each directory it monitors. Unfortunately, the default limit of watch handles may not be enough for reasonably sized projects (e.g. IntelliJ IDEA sources contain 30000+ directories). The current limit can be verified by executing:

    cat /proc/sys/fs/inotify/max_user_watches

    It can be raised by adding following line to the /etc/sysctl.conf file:

    fs.inotify.max_user_watches = 524288

    … and issuing this command to apply the change:

    sudo sysctl -p

    64-bit systems
    If your system is strictly 64-bit (i.e. doesn’t contains 32-bit runtime libraries in /lib32 directory) you should download 64-bit version here. Rename downloaded file to “fsnotifier”, rest of setup is same.