.
اطلاعات کاربری
درباره ما
دوستان
خبرنامه
آخرین مطالب
لینکستان
دیگر موارد
آمار وب سایت

مینیمالیسم یک سبک زندگی است که به افراد کمک می کند چیزهایی را که واقعاً به آنها نیاز دارند پیدا کنند و به زندگی آنها معنا ببخشد. ایده اصلی مینیمالیسم در واقع کمتر بودن نیست ، بلکه بیشتر بودن است. انتخاب مالکیت کمتر فقط شفافیت و تمرکز بر ارزشهایی است که می تواند چیزهایی را که واقعاً برای ما اهمیت دارند را برآورده کند.

برند ال جی همیشه ارتباط قوی با شعار شرکت خود را تداعی می کند: "زندگی خوب است." در واقع ، تأکید اصلی این پیام بر اهمیت ایجاد رشد و تغییر برای بهبود سبک زندگی با ایجاد یک تجربه تجاری منحصر به فرد از طریق فناوری های نوآورانه است.

برنامه مراقبت از مشتری مبتنی بر هوش مصنوعی LG ، که در لوازم خانگی پیشرو این شرکت استفاده می شود ، در مورد مصرف آب و انرژی به کاربران هشدار می دهد و توصیه های متفکرانه ای برای بهبود کارایی و صرفه جویی در هزینه ارائه می دهد. این یکی از نوآوری هایی است که شیوه زندگی ما را در این دهه بازتعریف می کند.

به همین ترتیب ، برند برتر LG SIGNATURE دارای مجموعه ای مملو از محصولات مینیمالیستی است تا فضای اضافی را خالی کند. تلویزیون LG SIGNATURE OLED R نمونه کاملی از این امر است و با این فلسفه طراحی شده است که تلویزیون هنگام تماشا نباید فضای زیادی اشغال کند. زیرا ال جی معتقد است داشتن اقلام کمتر در محیط کوچکتر می تواند به طرز شگفت انگیزی آرامش بخش و بیشتر مطابق با سبک زندگی مینیمالیستی باشد. این شیوه زندگی می تواند رهایی بخش باشد ، اما نباید آن را با ساده زیستی اشتباه گرفت. عملکرد بیشتر با هزینه کمتر به حداکثر رساندن تجربه داخلی است. ال جی به جای اینکه به این امر به عنوان یک تهدید نگاه کند ، این روند را یک فرصت می داند.

 

LG Objet یک راه حل ایده آل برای طراحان مینیمالیستی است که به دنبال لوازم جانبی مناسب برای ایجاد فضای بیشتر در اتاق ها هستند. این محصولات کاملاً منحصر به فرد با اشکال تجربی خود فضاهای خصوصی را ارائه می دهند. هر دستگاه در این مجموعه به گونه ای ساخته شده است که از نظر زیبایی منحصر به فرد است ، فضای کمتری را اشغال می کند و راحتی بیشتری را به زندگی روزمره می افزاید. تلویزیون هایی که می توانند به صورت کشویی حرکت کنند و فضای پنهان قابل استفاده در پشت صفحه را فراهم می کنند و دستگاه های تصفیه هوا که می توانند تلفن های هوشمند را کنار تخت شارژ کرده و تجهیزات مورد نیاز را تهیه کنند. آنها در این گروه قرار می گیرند.

LG Styler یک گزینه عالی برای علاقه مندان به خانه و مد است که به دنبال داشتن لباسشویی های حرفه ای بدون نیاز به اشغال یک اتاق کامل هستند. تنها کاری که باید انجام دهید این است که LG Styler پیشرفته را در کنار کمد لباس خود قرار دهید و از ویژگی های شگفت انگیز آن برای تهیه لباس بدون چین و چروک هیجان زده شوید.

ال جی نشان داده است که به عنوان یک شرکت آینده نگر ، متعهد به ایجاد نوآوری های جدیدی است که سبک زندگی مشتریان را ساده و غنی می کند.

 

 

http://lukasomhe95949.blogocial.com/--37232319

 

http://daltongctk04815.onesmablog.com/--41349437

 

http://edgargmzl04703.blogolize.com/--42079730

 

http://collinjbpa21086.bloguetechno.com/--37889670

 

http://andybysj05937.pointblog.net/--41779121

 

http://lukasnvzb18405.full-design.com/--45478177

 

http://elliottbcvm27169.thezenweb.com/--39698136

 

http://andrerhxi92580.tinyblogging.com/--44388792

 

https://cruzqdnq85407.affiliatblogger.com/54635818/شیوه-ارتباطی-جدید-روبات-های-خدماتی-ال-جی

 

https://miloeyqg93704.fitnell.com/43698256/شیوه-ارتباطی-جدید-روبات-های-خدماتی-ال-جی

 

https://donovanpldu38269.designertoblog.com/34122160/شیوه-ارتباطی-جدید-روبات-های-خدماتی-ال-جی

 

https://caidensnhy60482.blogs-service.com/34209730/شیوه-ارتباطی-جدید-روبات-های-خدماتی-ال-جی

https://keeganludk64273.bluxeblog.com/34761197/شیوه-ارتباطی-جدید-روبات-های-خدماتی-ال-جی

 

http://codykyjr48149.mpeblog.com/26944599/

 

http://daltonaefc95050.articlesblogger.com/26738601

 

 



:: بازدید از این مطلب : 138
|
امتیاز مطلب : 0
|
تعداد امتیازدهندگان : 0
|
مجموع امتیاز : 0
ن : zonelearning101
ت :
.

Improve your skills and workflow by exploring these five often overlooked aspects of Illustrator and typography. The difference between optical and metric crawling, how to use the Glyphs page, how to use Roman characters, how to use the hyphen correctly, and how to edit preferences to display large font previews ... all the things that are worth knowing.

1. Optical vs. Corning metric

 


Throughout Adobe CS, using the Character panel, you can automatically type the kernel using metric or optical kerning. Knowing which one to use and when is usually based on the font you use and the number of internal kernel pairs in the font. Automatic text, metric, or kerning is usually recommended, although if you use different fonts or sizes, you may want to consider the light settings because Illustrator adjusts the fonts for you. Optical adjustments can often yield better results for the type of display.


2. Glyph Panel
The Glyphs panel found in Illustrator and InDesign allows you to access the full font character set. You can find the Glyphs panel by going to Window> Type> Glyphs. Once opened, create a text field and then double-click on the glyph you want to use. Another point here is to check the whole family of a particular font, because you will notice that some characters only appear in italics. Three families with beautiful glyphs include Minion Pro, Burgues Script and Bickham Script Pro.

You may also be interested in a tutorial I wrote for Layers magazine: How to use the glyphs panel in Illustrator to create a font monster.


3. Roman hanging signs
Roman punctuation is a typographic area that is often overlooked, although in most cases its use can move a cleaner line to the edge of your body. This option is off by default, but you can turn it on in the Paragraph toolbar. In the Paragraph toolbar, click the small down arrow (see image below) to find additional options, and then click Hang Roman Marking. Here are some additional options that are all worth considering.


5. Large font preview
Choosing the right font for your particular project will not always be easy, so why not make it a little easier for yourself and increase the font size of your font. To do this, go to Edit> Preferences> Font Preview> Large. While here, you may want to consider other options in the settings panel, something that many designers overlook. It may just improve your workflow.


The distance line is not a dark line
There are three types of dashes and they should be used for their proper purposes (of course I am very lazy about this). Below are the definitions and ASCII codes required to use each dash with examples.

Dribbble
Awwwards
99designs
DesignCro...
Behance
See more
free graphic resources website
graphic resources for everyone
freepik
free design resources for commercial use
graphic design resources 2021
graphic burger
design resources website
graphic design resources 2020
freepikgraphic resources for everyonefree graphic resources websitefree design resources for commercial usegraphic design resources 2021graphic burger

 

https://prbookmarkingwebsites.com/story8205488/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://socialmediainuk.com/story8662172/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://bookmark-dofollow.com/story10154825/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://mediajx.com/story11170599/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://bookmark-template.com/story10149479/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://opensocialfactory.com/story7783804/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://dirstop.com/story8943463/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://ztndz.com/story10453608/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://gorillasocialwork.com/story8929798/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://socialrus.com/story8230172/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bookmarkport.com/story8795829/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bookmarkloves.com/story8864526/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://socialmediastore.net/story8757582/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bookmarkbirth.com/story8609127/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://socialnetworkadsinfo.com/story8838321/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://getsocialpr.com/story8902896/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bookmarkstumble.com/story4095022/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bookmarkstime.com/story9636412/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://gatherbookmarks.com/story9763437/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bookmarkrange.com/story10579774/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bookmarkextent.com/story10737874/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bookmarkspring.com/story4125600/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bookmarkswing.com/story10676333/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bookmarksknot.com/story10766435/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bookmarkja.com/story10719756/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://altbookmark.com/story10743126/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://letusbookmark.com/story10590616/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://trackbookmark.com/story10520390/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://hindibookmark.com/story10627971/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bookmarkshq.com/story10560952/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://nybookmark.com/story9758313/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bookmarketmaven.com/story9749537/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://johsocial.com/story10238898/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 

 


https://bouchesocial.com/story10243283/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://socialmarkz.com/story10236530/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://socialmphl.com/story10235969/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://sparxsocial.com/story10234249/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://socialclubfm.com/story10243798/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://sound-social.com/story10231667/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 

 


https://sociallawy.com/story10235622/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://socialdosa.com/story10235612/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://thesocialroi.com/story10234434/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://throbsocial.com/story10232103/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://bbsocialclub.com/story10237859/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://dftsocial.com/story10227565/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 


https://socialevity.com/story10236760/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 

 


https://nimmansocial.com/story10236763/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 

 


https://socialrator.com/story10232938/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 

 


https://social-lyft.com/story10222773/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 

 


https://socialskates.com/story10229378/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 

 


https://socials360.com/story10230693/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 

 


https://socialwoot.com/story10227771/fantastic-sites-for-downloading-free-background-images-for-commercial-use

 

 


https://bookmarkinglive.com/story10224645/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://bookmarkcork.com/story10226418/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://telebookmarks.com/story10223126/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://bookmarkedblog.com/story10226877/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://lingeriebookmark.com/story10231901/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://bookmarkspy.com/story10234511/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://bookmarkshut.com/story10212965/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://bookmarkvids.com/story10231170/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://fellowfavorite.com/story10225690/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://rotatesites.com/story10219646/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://hubwebsites.com/story10227754/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://binksites.com/story10224108/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://mysitesname.com/story10236069/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://sitesrow.com/story10230300/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://sites2000.com/story10233907/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://toplistar.com/story10224478/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://kingslists.com/story10225357/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://thejillist.com/story10229804/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://fatallisto.com/story10238125/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://worldlistpro.com/story10222903/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://mediajx.com/story11170724/free-graphic-resources-for-commercial-use


https://health-lists.com/story10222319/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://bookmark-dofollow.com/story10154939/free-graphic-resources-for-commercial-use


https://webcastlist.com/story10223901/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://bookmark-template.com/story10149604/free-graphic-resources-for-commercial-use


https://sirketlist.com/story10227895/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://listfav.com/story10222451/fantastic-sites-for-downloading-free-background-images-for-commercial-use


https://prbookmarkingwebsites.com/story8205616/free-graphic-resources-for-commercial-use



:: بازدید از این مطلب : 225
|
امتیاز مطلب : 0
|
تعداد امتیازدهندگان : 0
|
مجموع امتیاز : 0
ن : zonelearning101
ت :
.

Jython Syntax, Statements, and Comments

  •  The Interactive Console
  •  Line Separators and Block Indentation Syntax
  •  Comments
  •  Documentation Strings
  •  Statements
  •  Comparing Jython and Java

This chapter describes Jython's syntax and statements. Jython has a simple, clean syntax that produces easy-to-read code, often considered the antithesis to the intricate appearances of Java, C, or Perl. Before addressing syntax, this chapter introduces Jython's interactive mode. This mode allows you to enter code one line at a time like common shell consoles, and it is the perfect venue for exploring Jython's syntax.

What's Not Included in this Chapter

This chapter assumes you have a working installation of Jython. The Jython section of the New Riders website (www.newriders.com) will have a thourough section on installation if help is needed. Additionally, "What is Jython?" and Jython's associated praises are not addressed here. The "what" and "why" appear in the introduction and throughout the book.

The Interactive Console

Programming is often a succession of little puzzles. These little puzzles need to be worked out, tested, and confirmed before they can be added to the larger whole. That's where the interactive console comes in—you can explore code interactively, test things immediately, and experiment until the little puzzles are solved. The use of the interactive console, also called the interactive interpreter, is similar to shell programming, where you can enter commands interactively until they work, then place them in a file to make a shell script. The similarity fades when you realize that Jython itself is a very full and rich object-oriented programming language with a clean, easy-to-understand syntax.

The interactive console is started by running jython without any parameters or by adding the -i command-line switch. After starting Jython you should see something that looks similar to this:

Jython 2.0 on java1.2.2 (JIT: symcjit) 
Type "copyright", "credits" or "license" for more information. 
>>>_ 

The first line printed after starting Jython should include version information about Jython and Java as well as information about the JIT you are using. If you set the JAVA_COMPILER environment variable to NONE, Jython would confirm the change in JIT:

Jython 2.0 on java1.2.2 (JIT: NONE) 
Type "copyright", "credits" or "license" for more information. 
>>> 

The > > > in the third line is the prompt for the interactive interpreter. At this prompt you can type Jython code that is evaluated as each line is entered. There is also a second prompt, which is three periods, .... This is used when statements span multiple physical lines.

This testing, experimentation, and discovery within interactive mode is not limited to Jython. The interactive console is a powerful way of experimenting with and testing Java code. For this book, interactive mode is the primary means of learning Jython. Examples in the first part of this book are designed to be easy to experiment with, examine, and explore in interactive mode. The prompt symbols, > > > and . . ., are used to designate the use of the interactive interpreter throughout this book.

Line Separators and Block Indentation Syntax

Simple Jython statements are contained in a logical line. What is a logical line? you might ask. Java and many other languages make this clear with punctuation. The semicolon is a line-separator in Java. A simple Java print would be

System.out.println("Hello world"); 

Notice the semicolon. Now look at the comparable simple Jython print statement:

print "Hello world" 

There are no semicolons to mark the end of the logical line. The semicolon has been a standard for terminating lines in many languages, but in Jython, a newline is sufficient to denote the boundary between logical lines—with but a few exceptions. If a Jython print statement were entered into the interactive interpreter, pressing the Enter key would cause the interpreter to execute the contents of that logical line. The same goes for a Jython file. Separate lines of Jython code in a file are interpreted as separate logical lines, unless they fit one of the exceptions that follow.

There are cases in which the logical line for simple statements is not the same as the physical line. These cases are as follows:

  • Semicolon

  • Backslash

  • Open groupings

  • Triple-quotes

A Current Interactive Limitation

One disclaimer concerning the interactive interpreter: The current implementation of Jython produces an error when employing backslashes, open enclosures, and triple-quotes in interactive mode despite it being legal syntax. This syntax does work in Jython files as well as in the interactive interpreter for CPython (Jython's counterpart implemented in C). It could be working in interactive mode as well by the time you read this, but if not, those examples with extended logical lines should be placed in a file and run as an argument to the Jython interpreter (such as jython example.py).

Semicolon

The first case is the semicolon. This is the only case concerned with shortening the logical line. To place two or more logical lines on the same physical line, use the semicolon to separate statements. Even if there are not multiple statements on one line, the semicolon doesn't hurt anything. So, if Java programming habits lead to stray semicolons at the end of statements, no harm is done. Remember to be aware of code clarity when choosing this syntax to ensure that readability is not sacrificed for the sake of compactness.

Listing 1.1 has multiple print statements on one physical line. The semicolon acts as the logical-line separator between these two print statements. The second statement, however, does not have a semicolon, because the newline character after it functions as the separator.

Listing 1.1 Use of the Semicolon
>>># it's tradition, what can I say 
>>>print "Hello "; print "world" 
Hello 
world 

Notice that the print statement automatically inserted a newline. This is part of the behavior of Jython's print statement. If this is not desired, you can append a comma after the print statement which pre-pends a space to the second print statement instead:

>>>print "hello ",; print "world" 
hello world 

Backslash

The backslash (\) character is a line-continuation character. Multiple lines can be used to form one logical line with the \. An assignment is a simple Jython statement that binds a value to a variable, but what if you need to add so many values that they extended beyond the physical line? Listing 1.2 shows how the \ can be used to join multiple lines to do this. Listing 1.2 does not work interactively despite the legal syntax. To test Listing 1.2, place the code in a file (backslash.py used in example) and run it at the command line with jython backslash. py.

Listing 1.2 Line Continuations with the Backslash
# file: backslash.py 
var = 10 + 9 + 8 + 7 + 6 + \ 
5 + 4 + 3 + 2 + 1 

print var 

Results from running jython backslash.py at the command prompt:

55 

Open Groupings

Open groupings—meaning paired brackets [], braces {}, and parentheses ()— have their open (left) character on one line, and the closing character on a subsequent line. The logical line is extended until the closing half of these groupings appears. Listing 1.3 uses open groupings to spread a print statement over multiple physical lines. Listing 1.3 also does not work interactively despite being legal syntax (as of version 2.1a1).

Listing 1.3 Using Parentheses to Span Multiple Lines
# file: parens.py 
print ("this, " + 
       "that, " + 
       "the other thing.") 

Results from running jython parens.py:

this, that, the other thing 

The indentations on the second and third lines of listing 1.3 are for appearances—this is unrelated to the continuation of the logical line. Indention matters in Jython, but in the case of joining lines with \ or open enclosures, the indentation of the continued lines do not matter. It's the indentation of the first line that does. Indention rules are addressed with compound statements later.

Triple-Quotes

In Jython, you have the option to use three matching quotes to mark the start and end of a string, matching either """ or '''. In a triple-quoted string, newlines and contained quotes are all preserved except for another triple-quote. Listing 1.4 shows a triple-quoted string spanning multiple lines. Note how it preserves internal quotes plus newline characters. Listing 1.4 is legal syntax, but also does not work interactively.

Listing 1.4 Triple-Quoted Strings
# file: triplequote.py 
print """This is a triple-quoted string. 
Newlines and quotation marks such 
as " and ' are preserved in the string.""" 

Results from running jython triplequote.py:

This is a triple-quoted string. 
Newlines and quotation marks such 
as " and ' are preserved in the string. 

Code Blocks

With newline characters acting as the logical-line separators, it should be obvious that Jython already has much less punctuation than Java. What further reduces line noise is Jython's notation of code blocks in compound statements. These groupings, or "blocks" of code, are designated in Java by their enclosure in braces {}.

Here lies an important distinction—Jython does not use braces to group statements but rather uses a combination of the : character and indention whitespace. Java's braces handle multiple levels of groupings with multiple enclosures of braces, or braces within braces { {} }. Jython instead uses multiple levels of indention—one indention for first grouping, two indentions for the second, and so on. Listing 1.5 uses Jython's if statement to show how compound statements use the : and indention to denote groupings of code.

Listing 1.5 Indention-Based Groupings
>>>if 1: 
...    print "Outer" 
...    if 1: 
...        print "Inner" 
...    print "Outer- again" 
... 
Outer 
Inner 
Outer- again 

Notice how the execution of the compound statement happens only after the newline is entered at the leftmost margin in line six. This entry at the leftmost level notifies the interpreter that the indented grouping is completed and thus, the compound statement is completed.

What Is an Indention Level?

An indentation level can be anything that is consistent. Most common is each indention level being a tab, or four spaces. This would mean the second indention level would be either two tabs or eight spaces. Mixing tabs and spaces works too, so you can have the first indention be four spaces, the second indention a tab, the third equal to a tab and four spaces, and so on. The priority is consistency. It is also good to know what whitespace your editor is using so you can eliminate potential confusion when switching editors. What is legal and what is recommended differ. The most sensible recommendation is use four spaces indents and never mix tabs and spaces.

Comments

Looking back at Listing 1.1 from earlier in this chapter, we see another important feature.The # sign. This designates a comment. All code between the # sign and the end of the physical line is ignored by the interpreter. Its appearance is not restricted to the beginning of a line; it can appear after a statement like this:

print "Hello world" # It's tradition, what can I do 

The newline still terminates the logical line, but the space between # and the newline is treated as a comment and is ignored by the interpreter.

Another way to comment code is with anonymous string literals. If you do not assign a string to a variable, it is anonymous, and does not affect the namespace in which it appears. This makes strings useful as comments, especially triple-quoted strings because they allow comments to span multiple lines. Listing 1.6 shows different comments. Listing 1.6 does not currently work in the interactive interpreter as noted earlier.

Listing 1.6 Comments
# file: comments.py 
# This is a comment 
"This works for a comment" 
"""This comment can span 
multiple lines.  Code that you 
do not want executed can go 
in triple quotes, and it is safe 
to use other quotation marks within 
the triple quotes, such as: 
print "hello" """ 

There is no output from running jython comments.py.

Documentation Strings

The exploration and discovery mentioned when introducing interactive mode depends on introspection, the ability to look under the hood. An important Jython tool that helps when looking inside objects is Jython's self-documentation convention called doc strings. These are anonymous string literals appearing in function, method, and class definitions.

Listing 1.7 defines a function called foo. The second line of this example is an anonymous string literal, and a doc string because of its location. Note that this string is one indention level in as it should be as part of foo's code block. This doc string uses the triple-quote notation, but that is not required. Any legal string quoting works; triple-quotes just make it easier in case the documentation grows to more than one line.

Listing 1.7 Documentation Strings, __doc__
>>> def foo(): 
...     """This is an example doc string""" 
...      pass 
... 
>>> dir(foo) 
['__dict__', '__doc__', '__name__', 'func_closure', 'func_code', 
'func_defaults', 'func_doc', 'func_globals', 'func_name'] 
>>> foo.__doc__ 
'This is an example doc string' 
>>> 

The function dir() is a built-in function that looks at name bindings within a namespace. Listing 1.7 uses dir to look at function foo, and returns a list of names defined inside foo. In this list it is __doc__. Looking at the contents of foo.__doc__ show that it is the name bound to the doc string provided in the function definition. The actual results of calling dir(foo) differs between Jython 2.0 and Jython 2.1a1 (the current version as of this writing). Do not be concerned if your output differs slightly.

Statements

This section includes definitions and usage examples of Jython statements. Statements are categorized into simple statements, those with a single clause, and compound statements, those with multiple clauses or an associated code block.

Simple Statements

Simple statements are those Jython statements with a single clause, encompassing one logical line. These statements are often confused with built-in functions; however, there is a distinction. Statements are part of the syntax as opposed to functions or data objects defined within a namespace.

The following sections list Jython's simple statements and their syntax, and provides an example usage.

assert

The assert statement tests whether an expression is true and raises an exception if it is not true. If two expressions are supplied, the second expression will be used as the argument to the raised AssertException. Setting __debug__=0, and possibly the -O command-line switch in future releases, disables asserts.

Syntax:

"assert" expression [, expression] 

Example:

>>>a=21 
>>>assert a", line 1, in ? 
AssertionError: 
assignment

An assignment binds an object to an identifier. Jython has simple assignment (=) and augmented assignments ( + =, -=, *=, /=, * * =, %=, < < =, > > =, &=, |=, ^=).

Syntax:

variable assignment-operator value 

Example:

>>>var=3 
>>>print var 
3 
>>>var += 2 
>>>print var 
5 
break

The break statement terminates execution of an enclosing loop and continues execution after the loop block. This means it does skip the else block if it exists.

Syntax:

break 

Example:

>>>for x in (1,2,3,4): 
...    if x==3: 
...        break 
...    print x 
... 
1 
2 
>>> 
continue

The continue statement halts execution of the current loop block and start the enclosing loop again at its next iteration.

Syntax:

continue 

Example:

>>>for x in (1,2,3,4): 
...    if x==3: 
...        continue 
...    print x 
... 
1 
2 
4 
>>> 
del

The del statement removes a variable.The variable can be one within the namespace or a specific list or dictionary value.

Syntax:

"del"  identifier 

Example:

>>>a="foo" 
>>>print a 
foo 
>>>del a 
>>>print a 
Traceback (innermost last): 
  File "", line 1, in ? 
NameError: a>>> 
>>> a = [1,2,3] 
>>> del a[1] 
>>> print a 
[1, 3] 
exec

The exec statement executes Jython code. The exec statement requires an expression, which represents the code it needs to execute. A string, open file object, or code object can be supplied for this expression, which is the first parameter to exec(). If two parameters are provided, the second is used as the global dictionaries in which the code is executed. If three parameters are provided, the first is a dictionary used as the global namespace, and the second is the local namespace in which the code is executed.

Syntax:

"exec" expression ["in" expression ["," expression]] 

Example:

>>>exec "print 'The exec method is used to print this'" 
The exec method is used to print this 
>>> 
global

The global statement tells the parser to use global name bindings for listed identifiers throughout the current code block. Why? Because an assignment in a local code block identifies all references to that assigned variable as local. It's easier to see in the comparison of the following two code snippets:

>>>var = 10 
>>>def test(): 
...    print var # try and print the global identifier 'var' 
... 
>>>test() 
10 
>>> 

We see that var is found and prints. So far, so good. Now, what happens if we assign something to var after the print statement?

>>>var = 10 
>>>def test(): 
...    print var  # try and print the global identifier 'var' 
...    var = 20   # assign to 'var' in local namespace 
... 
>>>test() 
Traceback (innermost last): 
  File "", line 1, in ? 
  File "", line 2, in test 
NameError: local: 'var' 
>>> 

The identifier var is designated as local because of the assignment within the code block, so the print statement is an error because var does not exist yet in the local namespace. This is the reason for global.

Syntax:

global identifier ["," identifier]* 

Example:

>>>var = 10 
>>>def test(): 
...    global var # must designate var global first. 
...    print var  # try and print the global identifier 'var' 
...    var = 20   # assign to 'var' in local namespace 
... 
>>>test() 
10 
>>>print var  # check global 'var' 
20 
>>> 
import

The import statement locates and initializes what is imported and binds it to variables in the scope that import was called in. You can optionally change the name of the variables imports are bound to with an as new-name suffix to the import statement.

Syntax:

import module-name 
     OR 
from module-name import names 
     OR 
import module-name as new-name 
     OR 
from module-name import name as new-name 

Example:

>>>import sys 
>>>from java import util 
>>>import os as myOS 
>>>from sys import packageManager as pm 
pass

The "do nothing" statement. This statement is a placeholder.

Syntax:

pass 

Example:

>>>for x in (1,2,3,4): 
...    pass 
... 
>>> 
print

The print statement evaluates an expression, converts the result to a string if needed, and writes the string to sys.stdout or whatever file-like object it is directed to with the >> syntax. A file-like object is one with a write method defined.

Syntax:

print [expression] 
      OR 
print >> fileLikeObject, [expression] 

Example:

>>>print "Hello world" 
Hello world 
raise

The raise statement evaluates any expressions provided with it and raises an exception accordingly.

Syntax:

raise [expression [, expression [, traceback]]] 

Example:

>>>raise ValueError, "No value provided" 
Traceback (innermost last): 
  File "", line 1, in ? 
ValueError: No value provided 
return

The return statement ends execution of the method or function it is called in after evaluating any provided expression for use as a return value. If no expression is provided, the value None is returned.

Syntax:

return [expression] 

Example:

>>>def someFunction(): 
...    return "This string is the return value" 

Compound Statements

Compound statements are those statements that have a grouping or "block" of code associated with them. Flow control statements such as if, for, and while are compound statements. These are difficult to introduce without mentioning Jython's block indentation syntax. A code block, or grouping of statements, in Java is contained in braces {}. Multiple levels of groupings are in nested braces { {} }. This is not so for Jython. Rather, Jython uses the colon, :, and indentation to identify blocks of code. With this knowledge, we can define Jython's compound statements. The following sections explain Jython's compound statements and their definitions.

class

The class statement is used to define a class. Evaluation of a class statement defines a class in that current scope. Calling a class calls its constructor if defined and returns an instance of that class.

Syntax:

"class" name[(base-class-name)]: 

Example:

>>>class test:   # no base class 
...    pass      # place holder 
... 
>>>t = test()    # Calls class statement to make an instance 
def

The def statement is how functions and methods are defined.

Syntax:

"def" name([parameters]): 
    statements 

Example:

>>>def hello(person): 
...  print "Hello ", person 
... 
>>>hello("world")  # calls the hello function 
Hello world 
for

The for statement is a flow-control statement that iterates through a loop once for each member of a sequence. The for statement can also include an optional else clause that is executed after the sequence has expired.

Syntax:

"for" variable "in" expression":" 
    statements 
["else:"] 
    statements 

The expression provided must evaluate to a list.

Example:

>>>for x in (1,2,3): 
...    print x, 
...else: 
...    print "in else clause" 
... 
1 2 3 in else clause 
>>> 
if

The if statement executes a block of code conditionally when an expression evaluates to true.

Syntax:

if expression: 
    statements 
elif expression: 
    statements 
else: 
    statements 

If the first expression evaluates to false, the interpreter proceeds to evaluate the elif expression if provided. If all elif conditions are false, the else group of statements is executed.

Example:

>>>if a==b: 
...    print "variable a equals variable b" 
...elif a>b: 
...    print "variable a is greater than b" 
...else: 
...    print "variable a is less than b" 
try

The try statement executes a block of code until completion or until an error.

Syntax:

"try:" 
    statements 
"except" ["," expression ["," variable]]":" 
    statements 
["else:" 
    statements] 
   OR 
["finally:" 
    statements] 

Only one of the else or finally clause can be used, not both. If the try block of code runs without error, it proceeds to execute the block of code in its finally block. If the try block has an error, it stops execution of that block and proceeds to the except clause.

Example:

>>>try: 
...    1/0 
...except ZeroDivisionError, e: 
...    print "You cannot divide by zero:  ", e 
... 
You cannot divide by zero: integer division or modulo 
>>> 
while

The while statement executes a block of code as long as a provided expression evaluates to true.

Syntax:

"while" expression ":" 

Example:

>>>x = 10 
>>>while x>0: 
...    print x, 
...    x -= 1 
... 
10 9 8 7 6 5 4 3 2 1 

Comparing Jython and Java

Table 1.1 lists the statements used in Jython and compares them with Java's implementation.

Table 1.1. Jython Statements Compared to Java's

Statement

Comparison

assert

The assert does not have an immediate parallel in Java implementations previous to Java version 1.4

assignment

Jython and Java are similar in assignments despite there being some operator and scoping differences addressed later in this book.

break

Jython and Java break statements function the same.

continue

Jython and Java continue statements function the same.

del

The del statement in Jython does not have a Java counterpart.

exec

This has been confused with being a parallel to Java's exec method in the Runtime class. This is not the case, however. The Jython exec is for executing Jython code dynamically, whereas the Runtime exec in Java exists for running external system processes—not dynamically executing Java code.

global

Java does not have a direct parallel to Jython's global.

import

Java's import statement does not allow the binding of loaded classes to arbitrary names like Jython's import module as newName syntax. Nor does Java use the from module import name syntax. A simple comparison of similar Jython and Java import demonstrates these syntax differences:

Java: import javax.servlet.*;
Jython: from javax.servlet import *

 

pass

Java does not require a "do nothing" placeholder like pass because of the punctuation used in grouping code blocks. Java can have a code block do nothing by just having an empty set of braces— { } or a semicolon-terminated null string. Jython's sparse punctuation creates situations where the placeholder pass is required to make sense of the syntax.

print

Print is a statement in Jython. In Java, however, print is always a method of another object.

raise

Jython's raise statement is the parallel to Java's throw statement.

return

Jython and Java return statements function the same.

class

Jython and Java's class statements are similar in function but differ in syntax. A Jython class includes its base classes in parentheses after the class name, whereas Java uses the extends (class this extends that) syntax.

def

Method signatures in Java use a lot of information that Jython does not use. A signature like public int getID(String name) translates to def getID(name) in Jython. This brevity is because in Jython everything is public, and types are not explicitly declared.

for

The main difference is that Jython's for statement requires a sequence. It does not use the (variable, test, increment) used in Java. The first clause of a matching for loop in both Java and Jython would look like this:

Java: for (int x=10; x > 0; x++)
Jython for x in (10, 9, 8, 7, 6, 5, 4, 3, 2, 1):

Fortunately, Jython has the range() and xrange() functions to make sequences for Jython's for statement:

Jython: for x in range(10, 0, -1):

Java also lacks the optional else clause that exists in Jython's for statement.

if

Jython's if statement is similar to Java's, except that else if, as it is written in Java, is elif in Jython.

try

try/except/else/finally in Jython is the parallel to try/catch/finally in Java. They handle exceptions in their respective languages. In Jython, however, try/except/else and try/finally are two separate forms of the try statement that cannot be mixed.

while

Jython and Java while statements are similar, but Jython has an additional else clause that is executed when the condition evaluates to false.



:: بازدید از این مطلب : 144
|
امتیاز مطلب : 1
|
تعداد امتیازدهندگان : 1
|
مجموع امتیاز : 1
ن : zonelearning101
ت :
.
صفحات
نویسندگان
آرشیو مطالب
مطالب تصادفی
مطالب پربازدید
چت باکس
تبادل لینک هوشمند
پشتیبانی