如何用输出的man-page编写python脚本

时间:2016-06-02 06:55:58

标签: python bash shell man

我想知道如何使用stdout编写脚本,比如命令行,例如'更多' less',' man'似乎他们在另一层bash中显示了他们的结果。 如何在python中编写带有这样输出的程序?

1 个答案:

答案 0 :(得分:0)

您可以使用pydoc.pager。它在标准库中。

public class Home extends AppCompatActivity {

/* Views */
ProgressDialog progDialog;


/* Variables */
List<ParseObject> eventsArray = null;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    // ProgressDialog
    progDialog = new ProgressDialog(this);
    progDialog.setTitle(R.string.app_name);
    progDialog.setMessage("Loading...");
    progDialog.setIndeterminate(false);
    progDialog.show();

    // Call query
    queryEvents();
}



// MARK: - QUERY EVENTS
public  void queryEvents() {

    ParseQuery<ParseObject> query = ParseQuery.getQuery(Configs.EVENTS_CLASS_NAME);
    query.whereEqualTo(Configs.EVENTS_IS_PENDING, false);
    query.orderByAscending(Configs.EVENTS_END_DATE);
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> objects, ParseException error) {
            if (error == null) {
                eventsArray = objects;
                progDialog.dismiss();


                // CUSTOM GRID ADAPTER
                class GridAdapter extends BaseAdapter {
                    private List<ParseObject> objects;
                    private Context context;


                    public GridAdapter(FindCallback<ParseObject> context, List<ParseObject> objects) {
                        super();
                        this.context = (Context) context;
                        eventsArray = objects;
                    }

                    // CONFIGURE CELL
                    @Override
                    public View getView(int position, View convertView, ViewGroup parent) {
                        LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        View gridView;

                        if (convertView == null) {
                            gridView = new View(context);

                            // Get layout from event_cell.xml
                            gridView = inflater.inflate(R.layout.event_cell, null);

                            // Get title
                            TextView titleTxt = (TextView) gridView.findViewById(R.id.titleTxt);
                            if (eventsArray.get(position).getString(Configs.EVENTS_TITLE) != null) {
                                titleTxt.setText(eventsArray.get(position).getString(Configs.EVENTS_TITLE).toString());
                            } else { titleTxt.setText("N/A"); }




                        } else { gridView = (View) convertView; }

                        return gridView;
                    }

                    @Override
                    public int getCount() {
                        if (eventsArray != null) {
                            return eventsArray.size();
                        }
                        return 0;

                    }

                    @Override
                    public Object getItem(int position) {
                        return eventsArray.get(position);
                    }

                    @Override
                    public long getItemId(int position) {
                        return 0;
                    }
                }


                // Init GridView and set its adapter
                GridView eventsGrid = (GridView) findViewById(R.id.eventsGridView);
                eventsGrid.setAdapter(new GridAdapter(this, eventsArray));

                eventsGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                        Toast.makeText(getApplicationContext(), ((TextView) v.findViewById(R.id.titleTxt)).getText(), Toast.LENGTH_SHORT).show();

                    }
                });


                // Error in query
            } else {
                Toast.makeText(getApplicationContext(), error.getMessage().toString(), Toast.LENGTH_LONG).show();
            }

        }
    });

}


} //@end